skip to Main Content

I know how to display WordPress Current Post Title. It’s like this:

<?php echo do_shortcode('[auto_gallery search="' . get_the_title($post_id) . '"]'); ?>

I also know how to display Tag without the link. It’s like this:

<?php
$posttags = get_the_tags();
if ($posttags) {
  foreach($posttags as $tag) {
    echo $tag->name . ' '; 
  }
}
?>

My question is, how do I display the Current Tags inside my Shortcode?

Because the method below doesn’t work.

<?php echo do_shortcode('[auto_gallery search="' . get_the_tags($post_id) . '"]'); ?>

Any idea?
Please also teach me how to display Current Category inside my Shortcode.

Thanks for your help, I really appreciate it.

2

Answers


  1. <?php echo do_shortcode('[auto_gallery search="' . implode(" ",get_the_tags($post_id)) . '"]'); ?>
    

    get_the_tags() function return the array of tags and you need to pass the string in the shortcode so simply array to string conversion.

    Login or Signup to reply.
  2. You can use this way to display tags inside a Shortcode:

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
      foreach($posttags as $tag) {
    echo do_shortcode('[auto_gallery search="' . $tag->name . '"]');
      }
    }
    ?>
    

    I hope this helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search