Connect with us

Solved – WordPress short code not working with post_content

coding

Solved – WordPress short code not working with post_content

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 404 "Not Found"]');?>

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

Continue Reading
You may also like...
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

More in coding

To Top
Grab the largest plugin bundle from CodeCanyon!