Wordpress shortcodes do not render

2

I am developing a theme and I am applying shortcodes , but in the pages and in the entries, it shows me the literal text instead of what the shortcode returns.

I'm using the code that comes out in the API.

//[foobar]
function foobar_func( $atts ){
    return "foo and bar";
}
add_shortcode( 'foobar', 'foobar_func' );

When I put the text [foobar] in my post or on a page, it shows me that literal text.

I do not know what happens, I do not know if I'm skipping a configuration, if it's my environment, or something that escapes me.

Try the following code

add_shortcode( 'foobar', function( $atts ){
    return "foo and bar";
});

and neither.

single.php

<?php 
get_header(); ?>

<div class="container-fluid">
  <div class="row justify-content-center mt-4">
    <div class="col-md-8">
      <?php if ( have_posts() ): while ( have_posts() ): the_post(); ?>
      <article class="card">
        <div class="card-body">
          <h2 class="card-title"><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h2>
          <p class="lead"><?php echo get_the_content() ?></p>
        </div>
      </article>
      <?php endwhile; endif ?>
    </div>
  </div>
</div>
<?php get_footer();
    
asked by Franklin'j Gil'z 13.10.2018 в 01:05
source

1 answer

4

The error is in:

<?php echo get_the_content() ?>

Since you must print the content of the post with:

<?php the_content(); ?>

This happens because WordPress does not apply the the_content filter when calling the get_the_content () .

    
answered by 13.10.2018 / 01:42
source