V
V
Vladimir Novitsky2015-12-27 01:02:16
WordPress
Vladimir Novitsky, 2015-12-27 01:02:16

How to add get_home_url() to custom menu link (WP)?

Hello.
The meaning is this. Arbitrary links can be added to the WP menu. I need the link to look like: http://site.ru/#id1But I don't want to write down the site address. WP has a tag get_home_url()that adds the URL of the main page. But in the control panel, where menu items are edited:
b38e144c922d4c33b04bb16bc64d5e80.pngif you do this get_home_url()#id1, then garbage comes out, because PHP is not perceived there.
The question is, how can this be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WP Panda, 2015-12-27
@Novitsky

More or less like this

add_filter('wp_nav_menu_items','add_search_box_to_menu', 10, 2);
function add_search_box_to_menu( $items, $args ) {
        return preg_replace('/#/i', get_home_utl() . '#',$items);
}

M
Mr Crabbz, 2015-12-27
@Punkie

So just assign / # id1 - the link will go from the root. The truth is that wordpress should not be in a subfolder, but in the root of the domain.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question