How to show menu only in wordpress post? WordPress
Let me tell you that how to show menu only in wordpress post only and to hide on pages?
Step 1:
write the following code in functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
function register_custom_sidebars() { // Register a sidebar for posts register_sidebar( array( 'name' => __( 'Post Sidebar', 'textdomain' ), 'id' => 'post-sidebar', 'description' => __( 'Sidebar for posts', 'textdomain' ), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); // Register a sidebar for pages register_sidebar( array( 'name' => __( 'Page Sidebar', 'textdomain' ), 'id' => 'page-sidebar', 'description' => __
( 'Sidebar for pages', 'textdomain' ), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); } add_action( 'widgets_init', 'register_custom_sidebars' ); |
Step 2:
write the following code in sidebar.php
1 2 3 4 5 6 7 |
if ( is_single() && get_post_type() == 'post' ) { dynamic_sidebar( 'post-sidebar' ); } elseif ( is_page() ) { dynamic_sidebar( 'page-sidebar' ); } else { dynamic_sidebar( 'default-sidebar' ); } |
Step 3:
Go to Appearance – > widgets and select the menu for “post sidebar” only.