Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active March 19, 2024 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/067b123264cec4f7b875 to your computer and use it in GitHub Desktop.
Save billerickson/067b123264cec4f7b875 to your computer and use it in GitHub Desktop.
<?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 );
@guycarnegie
Copy link

Very useful Bill. thanks for this.
I've made this apply only to items which have a specific word in the post excerpt by using
if( strpos( get_the_excerpt(), 'Event' ) !== false)
but I'm stuck with making it only apply to items which are within the "Events" category.
if( strpos( get_the_category()[0], 'Event' ) !== false) crashes my page, potentially because the category list isn't passed, nor the Post ID actually, which I might have to use. Might you have any pointers?

@billerickson
Copy link
Author

Instead of checking the string position, you could use the WordPress function if ( has_category( 'event' ) ) { // do something }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment