Featured Post Shortcode
// Add Shortcode
function featured_post_shortcode( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'id' => '',
),
$atts,
'featured_post'
);
// Query
$the_query = new WP_Query( array ( 'p' => $atts['id'] ) );
// Posts
$output = '<div>';
while ( $the_query->have_posts() ) :
$the_query->the_post();
$output .= '<div>' . get_the_post_thumbnail() . '</div>';
$output .= '<h4>' . get_the_title() . '</h4>';
$output .= '<p>' . get_the_excerpt() . '</p>';
endwhile;
$output .= '</div>';
// Reset post data
wp_reset_postdata();
// Return code
return $output;
}
add_shortcode( 'featured_post', 'featured_post_shortcode' );