I am building a wordpress website and I want to show a text widget in the footer just for one page template. That widget shouldnot be seen for other pages. Is there any possible way for that?
3 Answers
There are a couple of options:
- Use a Plugin that adds contextual conditions to Widgets
Only output the
dynamic_sidebar()
in the page template in question. For example, if your custom page template is namedtemplate-foobar.php
, and the dynamic sidebar name isfooter-text-widget
:if ( 'template-foobar.php' == get_page_template() ) { dynamic_sidebar( 'footer-text-widget' ); }
Building on @Chip's answer, if you want to go down the plugin route, I sometimes use one called 'Custom Sidebars' (somewhat conveniently).
You'll be able to create your own sidebar (Appearance -> Custom Sidebars), and then add widgets to it (Appearance -> Widgets).
Then, you'll need to go to the page in question (Pages -> All Pages -> [Your Page]), and look for a new box called Sidebars that lets you select the sidebar you just created.
Use a filter, example:
function remove_the_widget( $regions ){
if(is_page('12')) {
$key = array_search('text-3', $regions['sidebar']);
if($key !== FALSE) {
unset($regions['sidebar'][$key]);
}
}
return $regions;
}
add_filter('sidebars_widgets', 'remove_the_widget');