• Resolved enricobt

    (@enricobt)


    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 );`

Viewing 1 replies (of 1 total)
  • Plugin Author Alexandru Tapuleasa

    (@talextech)

    Hi,

    There are many ways to disable a link but to keep it closer to what you started with, just replace the href value of “#” with “javascript:void(0)”

    So the full code would be:

    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 = 'javascript:void(0)';
                $link->set_attr( 'href', $redirect_url );        
            }
        }
    }, 10, 1 );
Viewing 1 replies (of 1 total)
  • The topic ‘external link do nothing’ is closed to new replies.