Title: Conditional Menu
Last modified: April 8, 2021

---

# Conditional Menu

 *  [devpar](https://wordpress.org/support/users/devpar/)
 * (@devpar)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/conditional-menu-5/)
 * Hi,
 * Long time user of this wonderful theme! I have created a page with a vertical
   header and added a menu ‘A’ to it. I am trying to change the menu on this page
   to menu ‘B’ through a function. Menu B is the main menu.
 *     ```
       add_action('wp', 'page_check');
       function page_check() {
           if (is_page('about')) {
             wp_nav_menu( array( 'theme_location' => 'main_menu') );
           }
       }
       ```
   
 * I have placed this code in functions.php, but menu ‘A’ isn’t changing to menu‘
   B’

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [devpar](https://wordpress.org/support/users/devpar/)
 * (@devpar)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/conditional-menu-5/#post-14296829)
 * The above page is created on the fly and doesn’t exist before creation, it inherits
   template from another page, that is the reason why we have to replace the existing
   menu.
 *  [Abhishek](https://wordpress.org/support/users/abhikr781/)
 * (@abhikr781)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/conditional-menu-5/#post-14312053)
 * Hello,
 * We are most certainly thankful for your feedback.
 * If it is a page then you can edit the age in WordPress, scroll down at the menu
   tab in the oceanwp settings section, and select a menu for that page.
 * Or you can also try to add the below snippet code in the function.php file and
   check.
 *     ```
       function prefix_custom_menu( $menu ) {
           if ( is_category( 'cptslug1' ) || is_category ( 'cptslug2' ) ) {
               $menu = 'catemenu';
           }
           return $menu;
       }
       add_filter( 'ocean_custom_menu', 'prefix_custom_menu' );
       ```
   
 * You can also use conditional tags according to need.
    [https://codex.wordpress.org/Conditional_Tags](https://codex.wordpress.org/Conditional_Tags)
    -  This reply was modified 5 years, 4 months ago by [Abhishek](https://wordpress.org/support/users/abhikr781/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Conditional Menu’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/oceanwp/4.2.2/screenshot.png)
 * OceanWP
 * [Support Threads](https://wordpress.org/support/theme/oceanwp/)
 * [Active Topics](https://wordpress.org/support/theme/oceanwp/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/oceanwp/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/oceanwp/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Abhishek](https://wordpress.org/support/users/abhikr781/)
 * Last activity: [5 years, 4 months ago](https://wordpress.org/support/topic/conditional-menu-5/#post-14312053)
 * Status: not resolved