I'd like to take an existing function and alter it's output depending on the page template used (WordPress). The below looks to see if an image is present, then outputs it with the text first then the image after, so the image is on the right hand side visually. This behaves the same on all templates.
I've done some research and tried a few things but can't seem to crack it. What I need is something that says if the page template is 'template_left.php' output the cta-image before the content. Likewise, if the page template is 'template_right.php' output the cta-image after the contnent.
All help and advice to edit the below gratefully received.
<?php
function call_to_action_shortcode($attrs, $content = null) {
$image = reset(rwmb_meta( "avenir_cta_image", 'type=image&size=large' ));
if ($image) {
$styles = "<style>
.cta-image {
background-image: url('{$image['url']}');
}
</style>";
$output = '<div class="page-cta row">' .
'<div class="content">' .
$content .
'</div>' .
'<div class="cta-image pull-right"></div>' .
'</div>';
return $styles . $output;
}
}
add_shortcode('call-to-action', 'call_to_action_shortcode');