Thanks for your question.
active_callback
is exactly what you’re looking for. You can use it with controls:
$wp_customizer->add_control(
'setting_name',
array(
'type' => 'text',
'section' => 'section_name',
'label' => 'Option with context',
'active_callback' => 'is_front_page'
)
);
and with sections:
$wp_customize->add_section(
'section-name',
array(
'title' => 'Section with context',
'active_callback' => 'is_front_page'
)
);
In examples above, this new setting/section will be visible only for front page, thanks to native is_front_page
function. You can also use other Conditional Tags.
But of course you can make your own contexts:
function mytheme_is_contact_page() {
return is_page_template( 'template-contact.php' );
}
function mytheme_is_page_id_123() {
return is_page( 123 );
}
Related Posts:
- Need help setting default setting value for radio button in theme customizer
- Is having multiple theme customizers for different pages possible?
- Remove Customize Background and Header from Appearance admin menu without CSS or JS
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- Dynamically change feature image in customiser
- One button to change all settings in theme customizer?
- Design view breaking on Pages
- Dynamically loaded Theme components based on Customizer Settings values : changes not appearing in Customizer preview – (Workaround found)
- Show different Customizer Settings on Page-Tamplates
- How to get custom image size for image uploaded in Customizer
- Passing array in add_option()
- Customizer: active_callback and sanitize_callback incompatibility?
- Skt full width basic slideshow problem
- WordPress Customizer Default Image
- Why is an array created in a function hooked to customize register populated when customizer is loaded but not when the front-end is loaded?
- Need advice on theme customizer and child themes
- Getting text from custom field from customizer
- require get_template_directory() . ‘path/to-my/file.php’ BREAKS customize > themes functionality
- Customizer: How to Sanitize a Decimal Number Range
- Use Custiomizer to setup meta theme color tag
- How to add button to top of theme customizer?
- How to store the_post_thumbnail() value in a variable
- PHP unit testing WordPress?
- List of all theme customizer control types?
- How to remove hardcoded characters from playlists?
- function_exists call in function.php
- Debugging an error: wp_enqueue_style was called incorrectly
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- Multiple do_shortcode($content) within one shortcode
- Remove css styles from specific page
- PHP Customization: Taxonomies and Queries, why? [closed]
- Widgets not showing in my custom theme
- Crop image from get_theme_mod Customizer field
- Get/Set wp.customize.previewer.previewUrl
- What is the fastest way to load PHP functions that are only used in one theme template?
- My Own layout in WooCommerce pages [closed]
- How do I access the media settings
- Can’t load WP function into external function
- Implement toggle switch for theme options in settings API
- Add child pages of parent to navbar PHP
- From where the header-text can be changed in WordPress custom header?
- Load a page into a div with Ajax
- Theme Options Page – User Updates Logo
- How to remove the cufon script from Dzonia Lite theme [closed]
- Add_action not working in required file of functions.php
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- Can’t access variable outside for loop
- add custom link to wordpress media gallery modal
- Improve page speed loading using CDN and async or defer attribute
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Displaying recent posts on static page with template-part via shortcode
- How to edit widget code to add unique class name to each div?
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- get_template_part for specific page
- How do I create my own .php file with a code part and echo it on different pages?
- WordPress admin-ajax.php
- Syntax error when I try to insert my loop into an unordered list? [closed]
- What exactly do this function declared into functions.php file of a WP theme?
- Royalty-Free Sliders used in theme development
- Reason to add a name of the theme like (‘menu-1’ => __( ‘Primary’, ‘twentynineteen’ ),) in PHP?
- How to check if a Customizer setting is set?
- zip unzip attachments in wordpress
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- WordPress get_media_embedded
- Warning: printf(): Too few arguments in helpers.php file
- get_comments_number() returns 0
- Why the dynamic_sidebar() call is putted into an ul tag?
- Toolbar Hidden in a Virtual Page
- Remove Custom Post Category In WordPress Slug Using .Htaccess
- PHP inside echo HTML
- Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
- Illegal string offset in PHP function in via Theme Customizer
- Header is not displaying on certain pages of wordpress theme [closed]
- Check if current post in loop is last on current page
- is_user_logged_in returns false when I access certain pages
- How can I edit a php custom page template to work in other themes?
- REST API custom endpoint to fetch pages and posts not working
- Looping through dummy posts and showing them in the main index.php
- Warning: count(): syntax problem of the count () function
- Fix hover images blink
- PHP code printed into CSS classes
- Get the image title and alt from custom query
- What syntax is this? “{{post.price}}”
- Problems with the WordPress loop [closed]
- How to replace hard-coded list of custom taxonomy terms based on custom field query [closed]
- Calling PHP function doesn’t work in index.php
- Access preview settings in php
- WordPress get_post_meta issue
- Listing current pages subp page in list items in the sidebar
- Trying to display ads on only a third of posts in a loop. Keep getting Error 500?
- Sidebar doesnt get updated?
- Add CSS class to PHP Statement
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- Load slideshow.css file only if Slideshow is checked / on
- Predefine Magazine Style Layouts
- Twig+WordPress how to use array arguments inside a function?
- orderby property of query on pre_get_posts returns incorrect value
- Woocommerce Convert existing order to the cart
- WordPress PHP8 Critical Error in class-wp-widget.php