WordPress v5.0.3: Not been able to check for gallery shortcode

46 views Asked by At

I am relatively new to WordPress development. Recently, I have installed WordPress 5.0.3 and been facing with a weird issue since then. All I am trying to do is to check if post contains gallery using has_shortcode function and passing gallery as tag to it.

Here's how the code looks like, the code is an excerpt from a custom page.php file.

<div class="container">
<?php
    $wpb_all_query = new WP_Query(array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1));?>

  <?php if ($wpb_all_query->have_posts()): ?>

  <?php while ($wpb_all_query->have_posts()): $wpb_all_query->the_post();?>

    <div class="row">
      <div class="col-12">
        <div class="d-flex justify-content-center">
          <?php esc_html(the_title());?>:&nbsp;<?php
if (has_shortcode(the_content(), 'gallery')):
    echo "TRUE";
else:
    echo "FALSE";
endif;?>
        </div>
      </div>

    </div>

    <?php endwhile;?>

<?php wp_reset_postdata();?>

<?php endif;?>

</div>

The function has_shortcode always returns false even if there is a gallery embedded inside a post.

Not sure, if this way of checking if a post contains a gallery still holds good in the present release.

I know the code is poorly formatted but didn't want to put time on formatting it here due to time constraints.

0

There are 0 answers