How do I create a post shortcode in wordpress?



How do I create a post shortcode in wordpress?..

Answer / Rajendra Prasad Meena

To create a custom post type shortcode in WordPress, follow these steps:
1. Create a new plugin or edit an existing one.
2. In the plugin's PHP file, add the following code: function my_custom_post_shortcode() {n $args = array(n 'post_type' => 'my_custom_post',n 'posts_per_page' => 5,n );n $loop = new WP_Query($args);n if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post();n the_title();n endwhile; endif;n }n Add this shortcode in your functions.php file or in a new shortcode plugin.
3. Use [my_custom_shortcode] anywhere in your posts and pages.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More WordPress Interview Questions

Is wordpress a software?

1 Answers  


Is wordpress secure?

1 Answers  


How we can disable comments in wordpress?

1 Answers  


How can you create a static page with WordPress?

1 Answers  


How to find out number of parameters passed into function?

1 Answers  


Is backupbuddy free?

1 Answers  


What is the function of wordpress?

1 Answers  


Explain which is the best multi-lingual plugin for wordpress?

1 Answers  


Can you have 2 themes in wordpress?

1 Answers  


Why is my wordpress not publishing?

1 Answers  


Can I download wordpress for free?

1 Answers  


How to find out the number of parameters passed into function?

1 Answers  


Categories