$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>homepage - How to show Home Page link in Wordpress Menu and how to add an icon to this?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

homepage - How to show Home Page link in Wordpress Menu and how to add an icon to this?

matteradmin9PV0评论

I tried with this code:

function home_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );


but gives me this error: Error 404 - Not Found

I would like that when I click on "Home Page" menu appears the recent posts.
And I would like to place an icon instead of "Home Page" writing.
Thank you!

I tried with this code:

function home_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );


but gives me this error: Error 404 - Not Found

I would like that when I click on "Home Page" menu appears the recent posts.
And I would like to place an icon instead of "Home Page" writing.
Thank you!

Share Improve this question asked Nov 3, 2011 at 13:52 humanbeinghumanbeing 231 gold badge1 silver badge4 bronze badges 5
  • How are you calling the menu in your template? In terms of the icon you can do that using CSS so it's not strictly WordPress related. You can get answers to that on stackoverflow – sanchothefat Commented Nov 3, 2011 at 14:08
  • @sanchothefat I called the menu in Appearance → Menus. – humanbeing Commented Nov 3, 2011 at 14:10
  • Do you have a set static page set as your home page? – Nicole Commented Nov 3, 2011 at 14:19
  • 1 "but gives me this error: Error 404 - Not Found" - this is a non-sequitur from the first part of your question. What action, specifically, gives you a Error 404 - Not Found. – Chip Bennett Commented Nov 3, 2011 at 14:28
  • You can also achieve it using this plugin wordpress/plugins/wp-home-page-menu – Vinod Dalvi Commented Mar 9, 2016 at 8:14
Add a comment  | 

2 Answers 2

Reset to default 3

To add a home link to menus that you create via the menus admin area:

  1. go to the Pages box,
  2. click the 'View All' tab
  3. 'Home' will appear, check the box and click 'add to menu'

If you programmatically want to add the HOME menu item in the main menu (primary) then you can do with the following code.

add_filter( 'wp_nav_menu_items', 'maple_custom_menu_filter', 10, 2 );
function maple_custom_menu_filter( $items, $args ) {
    /**
     * If menu primary menu is set.
     */
    if ( $args->theme_location == 'primary' ) {        

        $home = '<li class="menu-item"><a href="' . esc_url( get_home_url( '/' ) ) . '" title="'.esc_attr( get_bloginfo( 'name', 'display' ) ).'">Home</a></li>';
        $items = $home . $items;
    }

    return $items;
}
Post a comment

comment list (0)

  1. No comments so far