I have a set of local pages using a template, I want to display a widget only on pages where I have ticked the custom checkbox field.

  • 1
    Welcome to WordPress Development. What do you mean by "local pages"? What widget? What checkbox have you ticked and how is it stored? Additionally please share your research effort on this, thanks. – birgire Jan 17 '16 at 9:48

If you have a custom field (metadata) attached to a particular post, page or custom post type, you can do something like the following in your page template file:

Example example-template-file.php


    $sidebar_id           = 'my-custom-sidebar-id';
    $my_custom_meta_value = get_post_meta(get_the_ID(), 'my_custom_meta_key', true);

    if ( !empty($my_custom_meta_value) && is_active_sidebar($sidebar_id) ) {




Notes: dynamic_sidebar, is_active_sidebar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.