Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

recall background color for use in theme WordPress

  • SOLVED

I'd like to use the custom background color selected by the user in the admin panel to style other elements on the page.

Right now I have some other theme options where users can select colors and I use css in the head to style a few selectors used in the theme. I'd like to use the custom background color they select through the native WP interface to style some other elements. But I don't know how to access it.

If it's not possible, I'd can add my own background color selector in my theme options, but I'd like to somehow keep WPs ability to use a background image...

If this doesn't make sense, let me know. Thanks in advance.

Answers (3)

2010-07-03

Michael Fields answers:

This is how it works in TwentyTen:


$theme_settings = get_option( 'mods_Twenty Ten' );
print $theme_settings['background_color'];


Different themes will most likely have a different option name.


Steve Lambert comments:

Interesting, this might work... but where is this called? I don't see it in the functions.php or header.php of twentyten...


Michael Fields comments:

Steve, This is just example code that you can use to access the information that the user has stored. You will not find this code anywhere in TwentyTen. Basically, the theme allows a custom background to be added via: add_custom_background(); WordPress core then knows to enable theme support for this feature. It creates an interface that stores user-supplied data in the options table - a serialized array with an option name of 'mods_Theme Name'.

Just did a google search, and you should disregard my previous example. It will work just fine, but there is a better method:

get_theme_mod( 'background_color' );

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

Hope this helps,
-Mike


Steve Lambert comments:

indeed, that worked. Thanks!

2010-07-03

Rashad Aliyev answers:

Read this. I think that's useful for you.

http://wpframework.com/forums/topic/custom-body-background-colours-and-semantic-body-question


Steve Lambert comments:

I don't see the connection. I want to call the background color the user selects in the WP admin interface under Appearance > Background into the header - preferably as a hex value.

2010-07-03

Oleg Butuzov answers:

hm... i make a plugin that allow to set custom bg color for every page (post type == page) of the WP. is that you need?


Steve Lambert comments:

Hm, not really. Just looking to get the hex value for the color the user selects as the background. Thank you though!