How To Add Home Link To WordPress Menu Across Site Using Function.php

WordPress developers can create highly customized WordPress themes for clients and for sale. Developers can even customize WordPress, WordPress allows you to create child themes very easily.

With WordPress child themes you can very easily customize any WordPress theme. You can add new menus, widgets, sidebar or simply change color and font size of headings across your blog.

Normally when you register a new menu in a WordPress theme, you can go to WordPress dashboard to add links to your menu. But there is a small issue. You need to add all links yourself. Even Home link.

WordPress navigation menus do not Home link to WordPress menus by default. When you or your client create a new menu under WordPress dashboard (Appearance > Menus ), Home link must be added manually.

WordPress-menus-adding-custom-links-compressor
WordPress- Menus Adding custom links

But this is not a handy feature. Home link is one of the most important link on any website. Home link must be there in navigation menus, especially in the primary navigation menu.

So when you build WordPress themes, always add a Home link to navigation menus. It is not difficult as all. You can simply add a function to your theme’s functions.php file.

If you are not a developer, you are learning WordPress theme development. you can add a custom link to your WordPress themes very easily. Create a child theme and add following code in your child theme’s functions.php file.

function new_nav_menu_items($items) {
    $homelink = '<li class="home-link"><a href="' . home_url( '/' ) . '">' . __('Home') . '</a></li>';
    $items = $homelink . $items;
    return $items;
  }
  add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );

 

This simple function will add a Home link to your WordPress navigation menus. Here is a screenshot of a WordPress navigation menu with and without Home link.

How-To-Add-Home-Link-To-WordPress-Menu-Across-Site-Using-Function-compressor

That’s all.

it is very simple and easy to add a Home link to your WordPress navigation menus using functions.php file. You can add other custom links as well if you like.

Reference

I found this useful code at WordPress Forums. Thanks Rev. Voodoo for sharing this tip.

Leave a Reply

Your email address will not be published. Required fields are marked *