WordPress – Show the thumbnail and the title of a WP post with Bootstrap media

Add the following code to your theme’s functions.php file:

/*
 * Show the thumbnail and the title of a WP post with bootstrap media
 */
// Add the shortcode
add_shortcode('show_post_wp_bm', 'get_post_title_and_thumbnail_in_boostrap_media');

// Create the function
if(!function_exists('get_post_title_and_thumbnail_in_boostrap_media')):
	function get_post_title_and_thumbnail_in_boostrap_media($atts, $content=null)
	{
		// Get the attributes provided
		extract(shortcode_atts(array(
			"id" => null
		), $atts));
		
		// Check if an id was specified and that the post with that id exists
		if (is_numeric($id))
		{
			$post = get_post($id);
		}
		
		// Get the data
		if ($post != null) 
		{
			$title = apply_filters ( 'wp_title', $post->post_title);
			
			$html = '';
			
			$html .= '<div class="media">';
				$html .= '<div class="media-left media-middle">';
					$html .= '<a href="'.get_permalink($post).'" title="'.$title.'">';
						$html .= get_the_post_thumbnail($post, 'thumbnail');
					$html .= '</a>';
				$html .= '</div>';
				$html .= '<div class="media-body">';
					$html .= '<a href="'.get_permalink($post).'" title="'.$title.'">';
						$html .= '<h4 class="media-heading">'.$title.'</h4>';
					$html .= '</a>';
					//$html .= '...';
				$html .= '</div>';
			$html .= '</div>';
			
			// Return the content
			return html_entity_decode($html);
		}
		
		// Return an error
		return '[show_post_wp_bm] Invalid ID: ' . $id;
	}
endif;Code language: PHP (php)