Advertisement
SMSabuj

Some Simple Shrotcode

Sep 27th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.24 KB | None | 0 0
  1. function crazyland_static_content_display($attr, $content=null){
  2.     extract(shortcode_atts(array(
  3.         "tag" => "h1"
  4.     ), $attr));
  5.     return '<'.$tag.'>My static content</'.$tag.'>';
  6. }
  7. add_shortcode( "static-content", "crazyland_static_content_display");
  8.  
  9.  
  10. function crazyland_notice_shortcode($attr, $content=null){
  11.     extract(shortcode_atts(array(
  12.         "title" => "",
  13.         "text" => "",
  14.         "type" => "primary"
  15.     ),$attr));
  16.  
  17.     return '
  18.        <div class="alert alert-'.$type.'">
  19.            <h3>'.$title.'</h3>
  20.            '.$text.'
  21.        </div>
  22.    ';
  23. }
  24. add_shortcode( "notice", "crazyland_notice_shortcode" );
  25.  
  26.  
  27. function crazyland_image_shortcode($attr, $content=null){
  28.     extract(shortcode_atts(array(
  29.         "id" => "",
  30.         "title" => "",
  31.         "size" => "large"
  32.     ),$attr));
  33.     return '
  34.  
  35.        </h4>'.$title.'</h4>, <br/>, <img src="'.wp_get_attachment_url( $id, $size ).'" alt="">  
  36.    ';
  37. }
  38. add_shortcode( "img", "crazyland_image_shortcode" );
  39.  
  40.  
  41.  
  42. function crazyland_list_shortcode($attr, $content=null){
  43.     extract(shortcode_atts(array(
  44.         "items" => ""
  45.     ),$attr));
  46.  
  47.     $items_array = explode(',', $items);
  48.  
  49.     $my_html = '<ul>';
  50.  
  51.     foreach ($items_array as $item) {
  52.         $my_html .= '<li>'.$item.'</li>';
  53.     }
  54.     $my_html .= '</ul>';
  55.  
  56.     return $my_html;
  57. }
  58. add_shortcode( "list", "crazyland_list_shortcode" );
  59.  
  60. function crazyland_date_shortcode($attr, $content=null){
  61.     extract(shortcode_atts(array(
  62.         "format" => "M,D,Y"
  63.     ),$attr));
  64.  
  65.     return date($format);
  66. }
  67. add_shortcode( "date", "crazyland_date_shortcode" );
  68.  
  69. function crazyland_button_shortcode($attr, $content=null){
  70.     extract(shortcode_atts(array(
  71.         "style" => "",
  72.         "text" => "",
  73.         "type" => ""
  74.     ),$attr));
  75.  
  76.     return '
  77.            <button type="'.$type.'" class="btn btn-'.$style.'">'.$text.'</button>
  78.            ';
  79. }
  80. add_shortcode("button", "crazyland_button_shortcode");
  81.  
  82. function card_shortcode($atts, $content = null){
  83.     extract(shortcode_atts(array(
  84.         "width" => "288",
  85.         "title" =>"",
  86.         "text" => "",
  87.         "type" => "btn",
  88.         "style" =>"",
  89.         "size" => "thumbnail",
  90.         "id" =>"",
  91.         "content" => ""
  92.  
  93.     ),$atts));
  94.  
  95.     return '<div class="card" style="width:'.$width.'px">
  96.              <img class="card-img-top" src="'.wp_get_attachment_url($id, $size).'" alt="Card image cap">
  97.              <div class="card-body">
  98.                <h5 class="card-title">'.$title.'</h5>
  99.                <p class="card-text">'.$content.'</p>
  100.                <a href="#" class="'.$type.' btn-'.$style.'">'.$text.'</a>
  101.              </div>
  102.            </div>';
  103. }
  104. add_shortcode( "card", "card_shortcode" );
  105.  
  106.  
  107. function crazyland_maps_shortcode($atts) {
  108.    
  109.     $default = array(
  110.         'lat' => '22.9196383',
  111.         'lon' => '91.520781',
  112.         'zoom' => '16',
  113.         'width' => '600',
  114.         'height' => '400',
  115.     );
  116.  
  117.     $map_data = shortcode_atts( $default, $atts);
  118.  
  119.     $img = '<img src="http://maps.google.com/maps/api/staticmap?center=%f,%f&zoom=%d&size=%dx%d" />';
  120.  
  121.     return sprintf($img,$map_data['lat'],$map_data['lon'],$map_data['zoom'],$map_data['width'],$map_data['height']);
  122.  
  123. }
  124. add_shortcode( 'maps', 'crazyland_maps_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement