Latest Post

How To Creating Shortcode for post in Wordpress

How To Creating Shortcode for post in Wordpress


How To Creating Shortcode for post in Wordpress


This code use for you are create a Shortcode in your any function.php file.

Step-1

<?php
function  getShortcode(){
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 0,
);

$my_query = null;
$my_query = new WP_Query($args);
$city_arr = array();
if( $my_query->have_posts()) {
while ($my_query->have_posts()) : $my_query->the_post();
$meta=get_post_meta($my_query->post->ID);
the_title();
the_content();
endwhile;
}

}
add_shortcode('Shortcode', 'getShortcode');
?>

Step-2

//Add this code your wordpress page.
[Shortcode]

// Use shortcodes in form like Landing Page Template.
echo do_shortcode( '[Shortcode]' );

// Store the short code in a variable.
$var = do_shortcode( '' );

echo $var;

No comments