Shortcode
<?php
shortcode tutorial
https://www.smashingmagazine.com/2012/05/wordpress-shortcodes-complete-guide/
http://speckyboy.com/2011/07/18/getting-started-with-wordpress-shortcodes-examples/
//output code for html
<?php echo do_shortcode('[custom]') ;?>
//remove auto break <br /> from shortcode
function the_content_filter($content) {
$block = join("|",array("experience_heading", "single_experience"));
$rep = preg_replace("/(<p>)?\[($block)(\s[^\]]+)?\](<\/p>|<br \/>)?/","[$2$3]",$content);
$rep = preg_replace("/(<p>)?\[\/($block)](<\/p>|<br \/>)?/","[/$2]",$rep);
return $rep;
}
add_filter("the_content", "the_content_filter");
//--------------------Shortcode for heading change ---------------
function skill_heading_shortcode($atts){
extract(shortcode_atts(array(
'heading_1'=>'Our Skills',
'text'=>'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
), $atts));
return
'
<h2>'.$heading_1.'</h2>
<p>'.$text.'</p>
';
}
add_shortcode('skill_heading', 'skill_heading_shortcode');
//[skill_heading heading="" text=""]
//--------------------Shortcode for single post item---------------
function feature_post_item_shortcode($atts){
extract(shortcode_atts(array(
'icon'=>'bullhorn',
'heading'=>'Fresh and Clean',
'text'=>'Lorem ipsum dolor sit amet, consectetur adipisicing elit',
), $atts));
return '
<div class="col-md-4 col-sm-6 wow fadeInDown" data-wow-duration="1000ms" data-wow-delay="600ms">
<div class="feature-wrap">
<i class="fa fa-'.$icon.'"></i>
<h2>'.$heading.'</h2>
<p>'.$text.'</p>
</div>
</div>
';
}
add_shortcode('feature_single_post', 'feature_post_item_shortcode');
//[feature_single_post icon="" heading="" text=""]
//--------------------Shortcode for call data from custom post---------------
function custom_shortcode($atts){
extract( shortcode_atts( array(
'count' => '',
), $atts) );
$q = new WP_Query(
array('posts_per_page' => $count, 'post_type' => 'services')
);
$list = '<div class="row">';
while($q->have_posts()) : $q->the_post();
$idd = get_the_ID();
$service_icon = get_post_meta($idd, 'service_icon', true);
$list .= '
<div class="col-sm-6 col-md-4">
<div class="media services-wrap wow fadeInDown">
<div class="pull-left">
<img class="img-responsive" src="'.$service_icon.'">
</div>
<div class="media-body">
<h3 class="media-heading">'.get_the_title().'</h3>
'.get_the_content().'
</div>
</div>
</div>
';
endwhile;
$list.= '</div>';
wp_reset_query();
return $list;
}
add_shortcode('custom', 'custom_shortcode');
//--------------------Shortcode for call title & permalink---------------
function custom_shortcode($atts){
extract( shortcode_atts( array(
'type' => 'post',
'count' => '5',
), $atts) );
$q = new WP_Query(
array('posts_per_page' => $count, 'post_type' => $type)
);
$list = '<div class="wishlist_item_list">';
while($q->have_posts()) : $q->the_post();
$list .= '
<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>
';
endwhile;
$list.= '</div>';
wp_reset_query();
return $list;
}
add_shortcode('post_shortcode', 'custom_shortcode');
/*
[post_shortcode post="page" count="3"]
*/
//shortcode with feature_image
function team_member_shortcode($atts, $content=null){
extract(shortcode_atts(array(
'showpost'=>4,
'order'=>'ASC',
), $atts));
$li='<div class="container w"><div class="row centered"><br><br>';
$member_query=new WP_Query(array(
'post_type'=>'team',
'posts_per_page'=>$showpost,
'orderby'=>'menu_order',
'order'=>$order,
));
while($member_query->have_posts()):$member_query->the_post();
$member_name=get_post_meta(get_the_ID(), 'member_name', true);
$member_url=get_post_meta(get_the_ID(), 'member_url', true);
$li.='
<div class="col-lg-3">
'.get_the_post_thumbnail($post-ID, "member_image", array(
"class"=>"img-circle",
)).'
<h4>'.get_the_title().'</h4>
'.get_the_content().'
<p><a href="'.$member_url.'"> '.$member_name.' </a></p>
</div>
';
endwhile;
$li.='</div><br><br></div>';
return $li;
}
add_shortcode('team_member_shortcode', 'team_member_shortcode');
;?>