Using WordPress ‘popuplinks()’ PHP function

The popuplinks() WordPress PHP function adds element attributes to open links in new tabs.


popuplinks( $text );



popuplinks( 'Please visit <a href=""></a>.' );


Please visit <a href="" target="_blank" rel="external noopener"></a>


  • $text (string) – Required. Content to replace links to open in a new tab.

More information

See WordPress Developer Resources: popuplinks


Basic Usage

Add target="_blank" and rel="external" to a link.

$text = 'Visit <a href=""></a> for more info.';
echo popuplinks($text);

Add attributes to multiple links in a string.

$text = 'Check out <a href=""></a> and <a href=""></a>.';
echo popuplinks($text);

Preserving Existing Attributes

Preserve existing link attributes when adding new ones.

$text = '<a href="" class="my-link"></a>';
echo popuplinks($text);

Leave non-link content unchanged.

$text = 'Visit our <strong>WordPress</strong> site: <a href=""></a>';
echo popuplinks($text);

Using with Filters

Add popuplinks() to a filter hook to modify content automatically.

add_filter('the_content', 'apply_popuplinks');
function apply_popuplinks($content) {
    return popuplinks($content);