Site logo

Archived topic

Header Menu: Current Page

14 replies · Started by Andrey on February 28, 2018

Viewing posts 1–15 of 15

Hi.
Is it possible to remove a hyperlink from current page menu button? It is linking to itself now.

You can't remove the link, but you can make it so it doesn't do anything:

.main-navigation .main-nav ul li[class*="current-menu-"] > a {
    pointer-events: none;
}

Thank you, Tom!
Another question: is there any simple way to add custom icon to widget title?

The widget title field should accepts HTML. Is it not?

It's not. Or I don't know how to add it..

Hi Tom, Leo!
How to change the style of one menu item (font, background, size, margin-top, etc ..).
Does not work if I insert styles in this code:

.main-navigation .main-nav ul li[class*="current-menu-"] > a {
pointer-events: none;
}

Thanks for your support!

Additions to my previous message.
I need to change style of one menu item, so I inserted this code in the Menu Structure - Navigation Label:

<span style = "background-image: url (/images/01.gif); background-repeat: no-repeat; background-position: left center; padding: 0px 0px 0px 30px; color: # FF0000; font-family: Impact; font-size: 24px; "> MAIN PAGE </ span>

How to create a class with these parameters to include this class in the Menu Structure - CSS Classes?

Thank you.

Hi there,

Do you mind opening a new topic as yours isn't related to the original topic.

Thanks!

OK, no problem.

Thanks :)

You can’t remove the link, but you can make it so it doesn’t do anything:

Tom, I found some code. As planned, he should remove the link on the current page.

The first option removes the link to the current page in all menus:

function wp_nav_menu_no_current_link( $atts, $item, $args, $depth ) {
	if ( $item->current ) $atts['href'] = '';
	return $atts;
}
add_action( 'nav_menu_link_attributes', 'wp_nav_menu_no_current_link', 10, 4 );

The second option does the same for a specific menu:

function wp_nav_menu_no_current_link( $atts, $item, $args, $depth ) {
	if ( $args->theme_location == 'menu_name' ) {
		if ( $item->current ) $atts['href'] = '';
	}
	return $atts;
}
add_action( 'nav_menu_link_attributes', 'wp_nav_menu_no_current_link', 10, 4 );

I have a question: is it possible to do this or is it still not recommended?
Or does your code and the codes I have given do the same thing?

If your works for you then it's probably better than Tom's CSS.

There isn't a recommendation for this.

What about the SEO? How do both codes affect SEO?
I know that self-links (links to the current page) are bad for promotion.

I don't believe would have any effect on SEO but I'm not an SEO expert so might be best to check with someone like Yoast or Rankmath or even WordPress support team.

This archived topic is closed to new replies.