This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Using Newly Added Theme Options

  • Creator
    Topic
  • #7515
    eentrepreneur
    Participant

    Hi there

    I am quite new to customising WP themes, so this may be a stupid question:

    I would like to add an option to WPJumpstart with the options api to change the header color. I will be using the streched child theme. I understand how to add the option to the options page from the help files, but I don’t see how to actually use it. I can make this change manually in the child theme css file.

    Could you please tell me how to actually use this value to change the theme header colorafter I have added the option to the options page

    Thank you very much

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #7517
    Jason Bobich
    Keymaster

    Hello,

    So, after you’ve added an option, you’d utilize it within your site with the themeblvd_get_option function.

    http://dev.themeblvd.com/tutorial/get-a-theme-options-value/

    How you want to actually take an option and apply it is really up to you. Just in general, there’s really no way to easily incorporate a PHP element pulled from the database into a stylesheet. A more common approach would be to output some sort of styles in the <head> of your site.

    A basic example of just hooking styles to wp_head from your Child theme’s functions.php might look something like this:

    function my_styles(){
    	$my_color = themeblvd_get_option('my_custom_option');
    	?>
    	<style>
    	#top { background-color: <?php echo #my_color; ?> }
    	</style>
    	<?php
    }
    add_action('wp_head', 'my_styles');

    This will get the job done. But later on if you want to get more advanced, technically it’s better if your styles (whether they’re in a stylesheet or not) fall in with WordPress’s CSS enqueue system. You can accomplish that by utilizing wp_add_inline_style to attach a function to another stylesheet you’re enqueing.

    http://codex.wordpress.org/Function_Reference/wp_add_inline_style

    #7518
    eentrepreneur
    Participant

    Thank you very much Jason.

    Wow!! Excellent Support!!

    #7521
    eentrepreneur
    Participant

    Hi Jason

    I apologise, but I have one more question:

    I what file must I add the new theme options code? The child theme does not have an options.php file. Must I also add it to the child theme’s functions.php file? Or must I add it to the parent theme’s options.php file?

    Thank you very much

    #7530
    Jason Bobich
    Keymaster

    This will all go in your functions.php — In any WordPress theme, all of your PHP functionality that isn’t directly being outputted in a standard template file (i.e. header.php, footer.php, etc) goes in the functions.php.

    http://codex.wordpress.org/Functions_File_Explained

    As you accumulate more functionality, you can make things more organized with different files, but it all stems from functions.php. For example, take the options of the Parent Jump Start theme. You’ve got a functions.php -> which includes a themeblvd.php -> which includes theme-functions.php -> which includes an options.php file.

    http://php.net/manual/en/function.include.php

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.