Title: external link do nothing
Last modified: February 26, 2022

---

# external link do nothing

 *  Resolved [enricobt](https://wordpress.org/support/users/enricobt/)
 * (@enricobt)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/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 );`

Viewing 1 replies (of 1 total)

 *  Plugin Author [Alexandru Tapuleasa](https://wordpress.org/support/users/talextech/)
 * (@talextech)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/external-link-do-nothing/#post-15428671)
 * 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.

 * ![](https://ps.w.org/wp-external-links/assets/icon-256x256.png?rev=2103983)
 * [External Links - nofollow, noopener & new window](https://wordpress.org/plugins/wp-external-links/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-external-links/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-external-links/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-external-links/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-external-links/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-external-links/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Alexandru Tapuleasa](https://wordpress.org/support/users/talextech/)
 * Last activity: [4 years, 3 months ago](https://wordpress.org/support/topic/external-link-do-nothing/#post-15428671)
 * Status: resolved