суббота, 29 июня 2013 г.

Add/Rename “Home” link in WordPress

Blog posts in Wordpress appear mostly on the main page of the site. That’s why you need a link to it at the navigation bar. But some of the themes doesn’t have such a link. Another one has, but it’s called Home mostly. What if you want to rename it to Blog, for example? The thing is that can’t be fixed by WordPress configuaration. The only you can do is to update the theme source code by yourself.

The problem becomes even bigger if your site is not in English. You apply a good theme and… can’t do anything with “Home” label. Like NewsBelarus can’t.

There aren’t any standart way to fix it currently. Install and apply the theme. Then open the main page of your site with your browser (I’ve used Chromium, but Firefox+Firebug or Opera with debugger work fine too) and open Appearance -> Editor in another tab.

Check the source for the HTML around the menu items. Then check the php files of you theme for the place where it is generated. In the most of themes it’s placed in functions.php or header.php. Use menu and home as a keyword to seek in it.

When you’ve found the place, just update it depending on your case:

1) You have no “Home” link, your menu is generated with wp_list_pages(…) function
Write at the top of it another one <li>…</li> block with link to Home page with properly CSS classes.

2) Your menu is generated with wp_page_menu(…) function and you have no “Home” link, or you have “Home” link, but it isn’t written directly in wp_page_manu using ‘show_home’=>true Add ‘show_home’=>”Replacement_for_Home”. If wp_page_manu gets a string in this param, it will be put to Home link as a title.

3) The menu is generated with wp_page_menu or wp_nav_menu Seek in php files (it’s placed in functions.php mostly) for code (probably with another function names) that looks like this:

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

Replace

$args['show_home'] = true;

With

$args['show_home'] = "Replacement_for_Home";

If there aren’t such a lines, add them with properly $args["show_home"]. For wp_page_menu remove the custom menu in  Appearance -> Menus It works because this functions call wp_page_menu actually.

4) The “Home” text is hard-coded If you don’t need i18n, just replace it with the text you need. Otherwise replace it in English version, then put into _e(…) and translate in your language file. This hack is primitive, of course, but isn’t obvious.

Комментариев нет:

Отправить комментарий