Created
October 11, 2017 16:01
-
-
Save brianpurkiss/38c84f1da7363195cd58fd3960af1ef5 to your computer and use it in GitHub Desktop.
Bootstrap 4 Card WordPress Shortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function bootstrap_card( $atts, $content = null ) { | |
extract( shortcode_atts( array( | |
'width' => '300px', | |
'img' => '', | |
'title' => '', | |
'alt' => '' | |
), $atts ) | |
); | |
if ( empty($title) ) { | |
return ' | |
<div class="card" style="width:' . esc_attr($width) . '"> | |
<img class="card-img-top" src="' . esc_attr($img) . '" alt="' . esc_attr($alt) . '"> | |
<div class="card-block"> | |
<p class="card-text">' . esc_attr($content) . '</p> | |
</div> | |
</div> | |
'; | |
} else { | |
return ' | |
<div class="card" style="width:' . esc_attr($width) . '"> | |
<img class="card-img-top" src="' . esc_attr($img) . '" alt="' . esc_attr($alt) . '"> | |
<div class="card-block"> | |
<h5 class="card-title">' . esc_attr($title) . '</h5> | |
lorem ipsum | |
<p class="card-text">' . esc_attr($content) . '</p> | |
</div> | |
</div> | |
'; | |
} | |
} | |
add_shortcode('card', 'bootstrap_card'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment