Skip to content

Instantly share code, notes, and snippets.

@vevgeniy85
Last active February 19, 2019 13:08
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 vevgeniy85/3ce7e11f760da6bedc93e9656eb8d501 to your computer and use it in GitHub Desktop.
Save vevgeniy85/3ce7e11f760da6bedc93e9656eb8d501 to your computer and use it in GitHub Desktop.
WP - Banner Shortcode
// Add Shortcode
function akea_banner_shortcode( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'img' => 'https://dummyimage.com/1920x200/ccc/fff.jpg',
'alt' => '',
'url' => '',
'target' => '_self',
'width' => '100%',
'height' => 'auto',
),
$atts,
'banner'
);
$alt = ($atts['alt'] != '') ? ' alt="' . $atts['alt'] . '"' : ' alt=""';
$urlStyles = ' style="display: block;"';
$blockStyles = ' style="margin-bottom: 30px;"';
$output = '<div class="akea-banner-shortcode"' . $blockStyles . '>';
if ($atts['url'] != '') {
$output .= '<a ' . $urlStyles . ' href="' . $atts['url'] . '" target="' . $atts['target'] . '">';
}
$output .= '<img src="' . $atts['img'] . '"' . $alt . ' width="' . $atts['width'] . '"' . ' height="' . $atts['height'] . '">';
if ($atts['url'] != '') {
$output .= '</a>';
}
$output .= '</div>';
// Return code
return $output;
}
add_shortcode( 'banner', 'akea_banner_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment