php - Why do my [shortcodes] show as plain text from the WP editor? -


i'm trying use shortcodes execute tag-specific content loops on different pages of website. know shortcode function working properly, because when hardcode do_shortcode page template, shows perfectly.

but when try add [shortcode] directly wordpress editor instead, shows plain text. ideas how can fix this?

you can see i'm talking here - [showtag tag="seefour"] see plain text written directly wordpress text editor. it's not working correctly. below it, you'll see <?php echo do_shortcode("[showtag tag='seefour']"); ?> executing content loop page template.

any ideas how can fix this? hardcoding do_shortcode not sustainable me. site has 2 active plugins, problem persists after deactivating them, i'm @ loss.

for measure, content loop i'm trying execute:

function showtag_shortcode( $atts ) {     $atts = shortcode_atts( array(         'tag' => '', // default value.     ), $atts );      $posts = get_posts( 'tag=' . $atts['tag'] );     if ( $posts ) {       $output .= '<div class="jd-container">';       $output .= '<section class="jd-grid jd-pad1">';         foreach ( $posts $post ) {             setup_postdata( $post );             $output .= '<div class="jd-box">';             $output .= '<a href="' . get_the_permalink( $post ) . '">';             $output .= get_the_post_thumbnail( $post );             $output .= '<div class="jd-overlay"></div>';             $output .= '<div class="jd-overlay-text">';             $output .= get_the_title( $post );             $output .= '</div>';             $output .= '</a>';             $output .= '</div>';         }       $output .= '</section>';       $output .= '</div>';     } else {         $output = 'no data';     }     wp_reset_postdata();      return $output; }  add_shortcode( 'showtag', 'showtag_shortcode' ); 

and here's page.php template code:

<?php get_header(); ?>  <section class="jd-backdrop">   <div class="jd-trans-row jd-container">     <h2 class=""><?php the_title(); ?></h2>     <br>     <p class=""><?= get_post_field('post_content', $post->id) ?></p>   </div>   <?php echo do_shortcode("[showtag tag='seefour']"); ?> </section>  <?php get_sidebar(); ?> <?php get_footer(); ?> 

none of solutions i've found far have worked, i'm open suggestions...

it seems theme not execute do_shortcode() content of post.

try add following functions.php

function the_content_filter( $content) {     return do_shortcode( $content); }  add_filter( 'the_content', 'the_content_filter', 1000); 

update

from code of theme can see use get_post_field output content of post. unlike the_content(), function not invoke filters. why code above not work in case.

you have use get_post_field() in following manner:

<?php echo do_shortcode( get_post_field( 'post_content', $post->id ) ); ?> 

p. s. should avoid use <= doesn't work on hostings , discouraged.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -