Skip to content

Instantly share code, notes, and snippets.

@vanderwijk
Created March 10, 2021 09:32
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 vanderwijk/18acd549b099253eb222daf7757f1689 to your computer and use it in GitHub Desktop.
Save vanderwijk/18acd549b099253eb222daf7757f1689 to your computer and use it in GitHub Desktop.
Custom template example for shortcodes
<?php
function shortcode_template( $this_post ) {
try {
if ( has_post_thumbnail( $this_post->ID ) ) {
$thumb_id = get_post_thumbnail_id($this_post->ID);
$thumb_url = wp_get_attachment_image_src($thumb_id,'full', false);
$style = 'background-image: url('. $thumb_url[0] .')';
}
$retHtml = '<div class="grid-container full-height top-pad-30 bottom-pad-30 ' . basename(__FILE__) . '"><div class="grid-x grid-padding-x full-height align-middle">';
$retHtml .= '<div class="cell small-12 medium-6 medium-order-2">';
$retHtml .= apply_filters('the_content', $this_post->post_content);
$retHtml .= '</div>';
$retHtml .= '<div class="cell small-12 medium-6 medium-order-1">';
$retHtml .= '<div class="bg_img" style="'.$style.'"></div>';
$retHtml .= '</div>';
$retHtml .= '</div></div>';
} catch (Exception $ex) {
$retHtml = '<p>' . basename(__FILE__) . ': '.$ex->getMessage().'</p>';
}
return $retHtml;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment