简体   繁体   中英

Wordpress custom sidebar on single page

I'm trying to display a custom sidebar in a page. The code works with custom post types "news" posts but wont work with the page "na-midia". In the page the defaul sidebar is shown.

 // Custom Sidebar function prefix_custom_sidebar() { register_sidebar( array( 'name' => __( 'Custom Sidebar Mídia', 'page-builder-framework' ), 'id' => 'custom-sidebar', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="wpbf-widgettitle">', 'after_title' => '</h4>' ) ); } add_action( 'widgets_init', 'prefix_custom_sidebar' ); // Replace the default sidebar with our new custom sidebar on all docs posts function prefix_do_custom_sidebar( $sidebar ) { // this statement works for custom post types if( is_singular( 'news' ) ) { $sidebar ='custom-sidebar'; } // this statement NOT works for the page which is displaying the posts, display the default sidebar instead elseif ( is_singular( 'na-midia' ) ) { $sidebar ='custom-sidebar'; } return $sidebar; } add_filter( 'wpbf_do_sidebar', 'prefix_do_custom_sidebar' );

Solved!

 elseif ( is_page ( 'na-midia' ) ) { $sidebar ='custom-sidebar'; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM