Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Case Study shortcode

// Add Shortcode
function case_study_link_shortcode( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'id' => '',
		),
		$atts,
		'case-study'
	);

	if ( $atts['id'] ) {
	    $case_study_id = $atts['id'];
	} else {
	    $case_study = get_field('portfolio_project');
	    $case_study_id = $case_study_id[0];
	}
	
	$case_study_title = get_the_title($case_study_id);
	$case_study_url = get_the_permalink($case_study_id);
	$case_study_image = wp_get_attachment_image_src( get_post_thumbnail_id( $case_study_id ), 'portfolio-gallery' );
	
	ob_start(); ?><aside class="portfolio-single__case_study" style="background-image-url: url($case_study_image);">
	    <a href="<?php echo $case_study_url' ?>" class="portfolio-single__case_study__link">
	        <h1><?php echo $case_study_title; ?></h1>
	        <p>Read the case study now.</p>
	    </a>
	</aside><?php 
	return ob_get_clean();

}
add_shortcode( 'case-study', 'case_study_link_shortcode' );