Last active
September 27, 2015 14:07
-
-
Save billerickson/1281517 to your computer and use it in GitHub Desktop.
Add author to display posts shortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ""