Reputation: 96
I am having one issue and I don't know how to handle it. In Wordpress menu I am trying to add custom link menu item that will point to "mysitehomepage/#section-1"
In custom links I know how to point it to #section-1 but when user is on some other page (Blog, Contact or etc.) than that link is not pointing to #section-1 because that section only exist on homepage.
Of course this can be solved by adding mysite url before "/#section-1" but this is going to be a template for Wordpress so site url will be different every time. So I need some solution to get the link of my homepage + #section-1.
I hope I explained it good enough. :) And thanks.
Upvotes: 0
Views: 1490
Reputation: 402
Here is the code, that will add new item to the existing menu
Add it to functions.php file
function new_nav_menu_items($items) {
$homelink = '<li class="home"><a href="' . home_url( '/#section-1' ) . '">' . __('Home') . '</a></li>';
$items = $homelink . $items;
return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );
Upvotes: 1