I have created a shortcode to display a random custom post type.
I have placed the shortcode in a “Raw Element” within the cornerstone builder on the home page.
However the display of the shortcode is rendering at the top of the page just under the masthead area, and not where the raw element item is located.
Have you experienced this before? The output right now is just the post title and a thumbnail image.
// Shortcode to display Featured Machine
// ===========================================================
add_shortcode('featuredmachine', 'featured_machine_shortcode');
function featured_machine_shortcode() {
// Get the array of post ID's
$post_type_posts = get_random_id( 'machines' );
if ( $post_type_posts ) {
// Get the post object of the id first in line
shuffle( $post_type_posts );
$single_post = get_post( $post_type_posts[0] );
// echo '<pre>';
// print_r( $single_post) ;
// echo '</pre>';
// Display the post content
$title = $single_post->post_title;
$image = get_the_post_thumbnail( $single_post->ID, 'thumbnail' );
echo '<div><h2>' . $title . '</h2></div>';
echo '<div><a>' . $image . '</a></div>';
}
}
Screenshot of the Output.
