Remove Link from Title on Display Posts Shortcode

The Display Posts Shortcode plugin will display a list of posts matching your query, and the titles will be linked. This snippet will remove the links from the titles.

<?php
/**
* Remove Link from Title on Display Posts Shortcode
* @author Bill Erickson
* @link http://www.billerickson.net/code/remove-link-from-title-on-display-posts-shortcode
*
* @param $output string, the original markup for an individual post
* @param $atts array, all the attributes passed to the shortcode
* @param $image string, the image part of the output
* @param $title string, the title part of the output
* @param $date string, the date part of the output
* @param $excerpt string, the excerpt part of the output
* @param $inner_wrapper string, what html element to wrap each post in (default is li)
* @return $output string, the modified markup for an individual post
*/
function be_display_posts_unlink_title( $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class ) {
// Create a new title
$title = '<span class="title">' . get_the_title() . '</span> ';
// Now let's rebuild the output
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $excerpt . $content . '</' . $inner_wrapper . '>';
// Finally we'll return the modified output
return $output;
}
add_filter( 'display_posts_shortcode_output', 'be_display_posts_unlink_title', 10, 9 );
view raw functions.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer 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.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk