1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Is there any option or plug-in for changing all link to open in new window?

Discussion in 'WordPress' started by ahkip, Nov 11, 2006.

  1. #1
    Is there any hack that will add target="_blank" to all link inside a post?
     
    ahkip, Nov 11, 2006 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    What platform are you using?
     
    jestep, Nov 11, 2006 IP
  3. ahkip

    ahkip Prominent Member

    Messages:
    9,205
    Likes Received:
    647
    Best Answers:
    0
    Trophy Points:
    310
    #3
    Wordpress.
     
    ahkip, Nov 11, 2006 IP
  4. Zeo

    Zeo Active Member

    Messages:
    158
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Zeo, Nov 11, 2006 IP
  5. minstrel

    minstrel Illustrious Member

    Messages:
    15,082
    Likes Received:
    1,243
    Best Answers:
    0
    Trophy Points:
    480
    #5
    If you use the regular HTML post editor, and the "add link" edit button, there's an option in the popup to open in same window or open in new window.
     
    minstrel, Nov 12, 2006 IP
  6. 30k Challenge

    30k Challenge Peon

    Messages:
    1,188
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hmm I don't play with CSS too much but you might be able to put the base href target in the css for that content area.
     
    30k Challenge, Nov 13, 2006 IP
  7. JagoHarry

    JagoHarry Well-Known Member

    Messages:
    2,311
    Likes Received:
    178
    Best Answers:
    0
    Trophy Points:
    183
    #7
    JagoHarry, Nov 14, 2006 IP
  8. dct

    dct Finder of cool gadgets

    Messages:
    3,132
    Likes Received:
    328
    Best Answers:
    0
    Trophy Points:
    230
    #8
    I wrote a custom one a while ago that might help you out.

    Create a new php script in your plugin directory and add:
    
    /*
    Plugin Name: Change URLs to open in new window
    Description: This changes all external URLs to use the blank target (open in new window). It doesn't change local links
    */
    
    function BlankCallBack ($aMatches)
    {
    	$lFirstTime = 1;
    	foreach($aMatches as $lURL)
    	{
    		if($lFirstTime == 1)
    		{
    			$lFirstTime = 0;
    		}
    		else
    		{
    			// Done as a callback as we don't want internal links to open in new windows (as that would be annoying)
    			if(strpos($lURL, get_option('siteurl')) == false)
    			{
    				$lURLs .= "<a " . $lURL . " target=\"_blank\">";
    			}
    			else
    			{
    				$lURLs .= "<a " . $lURL . ">";
    			}
    		}
    	}
    	return($lURLs);
    }
    
    function st_target_blank( $aText ) {
    	$aText = preg_replace_callback('|<a (.+?)>|i', 'BlankCallBack', $aText);
    	return $aText;
    }
    
    add_filter('the_content', 'st_target_blank', 20);
    
    
    PHP:
    It's been live on my site for ages so it certainly works but looking at the code now it does look a bit messy :).
     
    dct, Nov 14, 2006 IP
    ahkip likes this.
  9. carl_in_florida

    carl_in_florida Active Member

    Messages:
    1,066
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    90