Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active January 3, 2019 22:39
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/c8b9245a5c4f6528d084f90832564921 to your computer and use it in GitHub Desktop.
Save billerickson/c8b9245a5c4f6528d084f90832564921 to your computer and use it in GitHub Desktop.
<?php
/**
* Display Posts default image
* @see https://displayposts.com/2019/01/03/display-default-image/
*/
function be_dps_default_image( $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class, $author, $category_display_text ) {
if( !empty( $original_atts['image_size'] ) && !empty( $original_atts['default_image'] ) && empty( $image ) ) {
$default_image_id = intval( $original_atts['default_image'] );
if ( $original_atts['include_link'] ) {
$image = '<a class="image" href="' . get_permalink() . '">' . wp_get_attachment_image( $default_image_id, $original_atts['image_size'] ) . '</a> ';
} else {
$image = '<span class="image">' . wp_get_attachment_image( $default_image_id, $original_atts['image_size'] ) . '</span> ';
}
if( !empty( $image ) )
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $category_display_text . $excerpt . $content . '</' . $inner_wrapper . '>';
}
return $output;
}
add_filter( 'display_posts_shortcode_output', 'be_dps_default_image', 10, 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment