Can WP Customizer work with single pages or posts?

Theme Customization API has been added in WP 3.4 and is described here: https://codex.wordpress.org/Theme_Customization_API

It makes it easy to add options such as “change background color” for themes. Such options will be stored in the database (in wp_options) with a name of your choice. You can then retrieve your value with get_option( 'field-name' );.

Read More

I’m wondering though if this works also with single posts or pages? So, is it possible to set different custom background color for each page with this tool and retrieve values using get_post_meta($id_of_the_current_post, 'field-name');?

Related posts

3 comments

  1. That’s not exactly what the theme customizer is for. The theme customizer should be reserved for big (global) items. Like the background color of every page, not just a single page. There isn’t a way (that I know of) to change things on a per page basis.

    For things that are page specific to the page/post, I’d recommend using the custom post meta. Here’s a pretty good example: http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/

  2. You can do this, though it may not be rich in documentation. The WP Customize control comes with WP_Customize_Control::active_callback(). On active callback, you can create an option that will only appear if you are in a post or a page or custom post type, etc…

    Read the sectionon “Contextual Controls” here. I apologize for not writting on a specific demo, but the author of this given post appears to be much better at demonstrating this.

Comments are closed.