WordPress.org

Forums

Expound
How to unregister menu locations? (4 posts)

  1. whoaloic
    Member
    Posted 1 year ago #

    Hello, I would like to use my custom menu locations so I register new menu locations.

    // Add Your Menu Locations
    function register_my_menus() {
      register_nav_menus(
        array(
        	'top' => __( 'Top Navigation' ),
        	'main' => __( 'Main navigation' )
        )
      );
    }
    add_action( 'init', 'register_my_menus' );

    But how to unregister expound primary and social menu locations?
    I try this:

    unregister_nav_menu( array(
    'primary' => __( 'Primary Menu', 'expound' ),
    		'social' => __( 'Social Menu', 'expound' ),
    ));

    But it did not work.
    Regards.

  2. LinuxPanda
    Member
    Posted 1 year ago #

    Create a child theme and in functions.php, you can override the "expound_setup" function and add custom menu.

    <?php
    
    /**
     * Add action to remove parent function "expound_setup" using function "remove_expound_setup"
     * Parent theme uses the default priority of 10
     * So use a priority of 9 to load before the parent theme
     */
    add_action( 'after_setup_theme', 'remove_expound_setup', 9 );
    
    // Remove parent function "expound_setup" and override it with "override_expound_setup" function
    function remove_expound_setup () {
    	remove_action( 'after_setup_theme', 'expound_setup' );
    	add_action( 'after_setup_theme', 'override_expound_setup' );
    }
    
    if ( ! function_exists( 'override_expound_setup' ) ) :
    /**
     * Sets up theme defaults and registers support for various WordPress features.
     *
     * Note that this function is hooked into the after_setup_theme hook, which runs
     * before the init hook. The init hook is too late for some features, such as indicating
     * support post thumbnails.
     */
    function override_expound_setup() {
    
    	/**
    	 * Custom template tags for this theme.
    	 */
    	require( get_template_directory() . '/inc/template-tags.php' );
    
    	/**
    	 * Custom functions that act independently of the theme templates
    	 */
    	require( get_template_directory() . '/inc/extras.php' );
    
    	/**
    	 * Customizer additions
    	 */
    	require( get_template_directory() . '/inc/customizer.php' );
    
    	/**
    	 * Make theme available for translation
    	 * Translations can be filed in the /languages/ directory
    	 * If you're building a theme based on Mag, use a find and replace
    	 * to change 'expound' to the name of your theme in all the template files
    	 */
    	load_theme_textdomain( 'expound', get_template_directory() . '/languages' );
    
    	/**
    	 * Add default posts and comments RSS feed links to head
    	 */
    	add_theme_support( 'automatic-feed-links' );
    
    	/**
    	 * Editor styles for the win
    	 */
    	add_editor_style( 'css/editor-style.css' );
    
    	/**
    	 * Enable support for Post Thumbnails on posts and pages
    	 *
    	 * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
    	 */
    	add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 220, 126, true );
    	add_image_size( 'expound-featured', 460, 260, true );
    	add_image_size( 'expound-mini', 50, 50, true );
    
    	/**
    	 * This theme uses wp_nav_menu() in one location.
    	 */
    /*
     * Original menu for reference
     *
     *
     	register_nav_menus( array(
    		'primary' => __( 'Primary Menu', 'expound' ),
    		'social' => __( 'Social Menu', 'expound' ),
    	) );
    *
    *
    * */
    	register_nav_menus( array(
    		'top' => __( 'Top Navigation' ),
    		'main' => __( 'Main navigation' )
    	));
    
    	/**
    	 * Enable support for Post Formats
    	 */
    	add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
    
    	/**
    	 * Enable support for Custom Background
    	 */
    	add_theme_support( 'custom-background', array(
    		'default-color' => '333333',
    	) );
    }
    endif; // expound_setup
  3. LinuxPanda
    Member
    Posted 1 year ago #

    A small correction.

    We should use priority of "11 or higher" to make sure the child theme functions will be loaded last.

    So the correct code will be,

    <?php
    
    /**
     * Add action to remove parent function "expound_setup" using function "remove_expound_setup"
     * Parent theme uses the default priority of 10
     * We are using priority 99 to make sure the child theme functions will be loaded last
     */
    add_action( 'after_setup_theme', 'remove_expound_setup', 99 );
    
    // Remove parent function "expound_setup" and override it with "override_expound_setup" function
    function remove_expound_setup () {
    	remove_action( 'after_setup_theme', 'expound_setup' );
    	add_action( 'after_setup_theme', 'override_expound_setup' );
    }
    
    if ( ! function_exists( 'override_expound_setup' ) ) :
    /**
     * Sets up theme defaults and registers support for various WordPress features.
     *
     * Note that this function is hooked into the after_setup_theme hook, which runs
     * before the init hook. The init hook is too late for some features, such as indicating
     * support post thumbnails.
     */
    function override_expound_setup() {
    
    	/**
    	 * Custom template tags for this theme.
    	 */
    	require( get_template_directory() . '/inc/template-tags.php' );
    
    	/**
    	 * Custom functions that act independently of the theme templates
    	 */
    	require( get_template_directory() . '/inc/extras.php' );
    
    	/**
    	 * Customizer additions
    	 */
    	require( get_template_directory() . '/inc/customizer.php' );
    
    	/**
    	 * Make theme available for translation
    	 * Translations can be filed in the /languages/ directory
    	 * If you're building a theme based on Mag, use a find and replace
    	 * to change 'expound' to the name of your theme in all the template files
    	 */
    	load_theme_textdomain( 'expound', get_template_directory() . '/languages' );
    
    	/**
    	 * Add default posts and comments RSS feed links to head
    	 */
    	add_theme_support( 'automatic-feed-links' );
    
    	/**
    	 * Editor styles for the win
    	 */
    	add_editor_style( 'css/editor-style.css' );
    
    	/**
    	 * Enable support for Post Thumbnails on posts and pages
    	 *
    	 * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
    	 */
    	add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 220, 126, true );
    	add_image_size( 'expound-featured', 460, 260, true );
    	add_image_size( 'expound-mini', 50, 50, true );
    
    	/**
    	 * This theme uses wp_nav_menu() in one location.
    	 */
    /*
     * Original menu for reference
     *
     *
     	register_nav_menus( array(
    		'primary' => __( 'Primary Menu', 'expound' ),
    		'social' => __( 'Social Menu', 'expound' ),
    	) );
    *
    *
    * */
    	register_nav_menus( array(
    		'top' => __( 'Top Navigation' ),
    		'main' => __( 'Main navigation' )
    	));
    
    	/**
    	 * Enable support for Post Formats
    	 */
    	add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
    
    	/**
    	 * Enable support for Custom Background
    	 */
    	add_theme_support( 'custom-background', array(
    		'default-color' => '333333',
    	) );
    }
    endif; // expound_setup
  4. LinuxPanda
    Member
    Posted 1 year ago #

    Its not working the way it should with priority greater than 10.

    So the priority should be "9 or less" for this particular function since we are overriding the function.

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic

Tags

No tags yet.