Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active September 27, 2015 14:07
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/1281517 to your computer and use it in GitHub Desktop.
Save billerickson/1281517 to your computer and use it in GitHub Desktop.
Add author to display posts shortcode
<?php
/**
* Add Author to Display Posts Shortcode plugin
* @author Bill Erickson
* @link http://wordpress.org/extend/plugins/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
*/
add_filter( 'display_posts_shortcode_output', 'be_display_posts_facebook', 10, 7 );
function be_display_posts_facebook( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper ) {
// Here's the author
$author = '<span class="author">by ' . get_the_author() . '</span>';
// Now let's rebuild the output and add the $author to it
$output = '<' . $inner_wrapper . ' class="listing-item">' . $image . $title . $date . $author . $excerpt . '</' . $inner_wrapper . '>';
// Finally we'll return the modified output
return $output;
}
@foxytom
Copy link

foxytom commented Apr 11, 2013

This is my first Gihub comment so apologies for any noobness.

Is there not an error on line 21 whereby there should NOT be a quote before "by" and there SHOULD be a quote after ""

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