You have three options:
- Register a dynamic sidebar for a specific page, and then create a page template that calls
dynamic_sidebar()
for the registered sidebar. - Use an
is_page( $id )
conditional wrapper in yourpage.php
template - Output Widget code conditionally, using
is_page( $id )
Custom Page Template
The first option would include your register_sidebar()
call in functions.php
:
register_sidebar( array(
'name' => 'Specific-Page Sidebar',
'id' => 'specific-page-sidebar'
// other array parameters omitted for brevity
) );
Then, you create a custom page template, e.g. template-test-sidebar.php
.
Then, in the appropriate place in the custom page template, invoke the specific sidebar, via dynamic_sidebar()
:
dynamic_sidebar( 'specific-page-sidebar' );
is_page()
conditional in page.php
The second option is more simple, but less dynamic, as it requires you to hard-code the page ID into the template. Simply wrap dynamic_sidebar()
in an is_page()
conditional:
if ( is_page( $id ) ) {
dynamic_sidebar( 'specific-page-template' );
}
Conditional Widget Output
The third method involves conditional output of the Widget itself, which generally requires use of a Plugin, such as Widget Logic or any of several other related Plugins.
With this method, you don’t need to register a separate dynamic sidebar. You simply use one of your existing sidebars, and then the Plugin provides an in-Widget option to specify the conditional logic to use, such as is_page( $id )
to determine if the Widget should be displayed.