Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

Solved – WordPress Short code not working with post_content

Hello Friends,

I am continuously working with WordPress since last few years. In one of my project, my client was facing a problem with short code. My Client uploads an image and add Caption. Caption is added and it looks fine with WP Editor. But when he view that page in front end, it shows short code itself instead of real converted short code html. I searched for the same and found that short code works with the_content or get_the_content. I used $post->post_content for custom post type. This means WordPress Short code not working with post_content.

To solve this and convert short codes, you just need to write below code. You need to use the_content() function which convert short codes automatically.

<?php
if( have_posts() ) {
  while (have_posts()) : the_post();
    the_content();
  endwhile;
}
?>

If you are unable to write such code and wanted to convert short codes, than you can also use below function.

<?php do_shortcode('[shortcode_here]');?>
 
For e.g.
<?php do_shortcode('[contact-form-7]');?>

Using this function, you can convert short code manually. Let me know if you are facing any problem with this.

Share:

No Comments Yet.

Leave a Reply

Your email address will not be published.