external link do nothing
-
Hello,
I would need to disable specific old links so that when the user clicks on them, the link does nothing.
I changed your action example and it works fine by replacing all my “//old-site.it” URLs with “#” but then I should add a new attribute, for example, ‘onclick=”return false;”‘, that would allow “do nothing” effect.
How can I do this and change this action code?
Please see my code below.
Thank you
Enrico
—
add_action( ‘wpel_link’, function ( $link ) {
// check if link is an external links
if ( $link->is_external() ) {
// get current url
$url = $link->get_attr( ‘href’ );
if ( strpos($url,’//my-old-site.it/’ ) !== false ) {
$redirect_url = “#”;
$link->set_attr( ‘href’, $redirect_url );// echo ‘onclick=”return false;”‘;
}
}
}, 10, 1 );`
- The topic ‘external link do nothing’ is closed to new replies.