In the first function mentioned, there is a small typo in the code. For wp_nav_menu there is ‘remove_title_attre‘ but it should be like the rest ‘remove_title_attr’.
Also, I am not sure that regular expression is correct. It took my url ‘https://my-website/some-page’ and made it ‘https://my-website/\#\’. If that’s the intent that’s fine, but I thought it would need to be href=”#”. I am not a master of regex so I can only provide a link to Smashing Mag that describes them in detail: https://coding.smashingmagazine.com/2009/06/01/essential-guide-to-regular-expressions-tools-tutorials-and-resources/.
But I believe it should be like this:
preg_replace('/href=\"(.*?)\"/', 'href="#"', $nav );
TIP: I prefer to use ‘javascript:void(0);’ to prevent any respond from a click.
So the code I used is:
function remove_title_attr( $nav )
{
return $nav = preg_replace('/href=\"http:\/\/nolink\"/', 'href="javascript:void(0);"', $nav );
}
add_filter( 'wp_nav_menu', 'remove_title_attr' );
add_filter( 'wp_page_menu', 'remove_title_attr' );
Where I simply put ‘nolink’ into a Custom URL in WordPress and it shows as href=”https://nolink” which is replaced by regular expression and transformed into href=”javascript:void(0);”.
WILL NOT WORK FOR CATEGORY LINKS THOUGH.
mYrAn – I know you’re looking to remove the link completely in your Admin side, but I cannot help you with that at the moment.