Open links in a new window

The links in Display Posts all open in the current window. We can use the output filter to modify this, making all links open in a new window:

This code snippet goes in a core functionality plugin or Code Snippets.

/**
 * Display Posts, open links in a new window
 * @see https://displayposts.com/2019/02/20/open-links-in-a-new-window/
 *
 */
function be_dps_links_new_window( $output ) {
	$output = str_replace( 'href="', 'target="_blank" href="', $output );
	return $output;
}
add_filter( 'display_posts_shortcode_output', 'be_dps_links_new_window' );

Filters used:

Published by Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributor to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.