Menu bar

Wednesday 30 December 2015

How to show or hide widgets on specfic pages?

The current sample is setup to only display the core ‘pages’ widget on the contact page only. Don’t forget that is_page also accepts an array of page names and id’s.


add_filter( 'widget_display_callback', 'hide_widget_pages', 10, 3 );

function hide_widget_pages( $instance, $widget, $args ) {
  
if ( $widget->id_base == 'pages' ) { // change 'pages' to widget name
     
if ( !is_page( 'contact' ) ) {    // change page name
         
return false;
     
}
  
}
}

No comments: