Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active February 19, 2019 19:17
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/1c46f775812304a67f21d4b8659148c1 to your computer and use it in GitHub Desktop.
Save billerickson/1c46f775812304a67f21d4b8659148c1 to your computer and use it in GitHub Desktop.
<?php
/**
* Template Parts with Display Posts Shortcode
* @author Bill Erickson
* @see https://www.billerickson.net/template-parts-with-display-posts-shortcode
*
* @param string $output, current output of post
* @param array $original_atts, original attributes passed to shortcode
* @return string $output
*/
function be_dps_template_part( $output, $original_atts ) {
// Return early if our "layout" attribute is not specified
if( empty( $original_atts['layout'] ) )
return $output;
global $be_dps_atts;
$be_dps_atts = $original_atts;
ob_start();
get_template_part( 'partials/dps', $original_atts['layout'] );
$new_output = ob_get_clean();
if( !empty( $new_output ) )
$output = $new_output;
return $output;
}
add_action( 'display_posts_shortcode_output', 'be_dps_template_part', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment