• Is it possible to replace “test” text from this shortcode

    <?php echo do_shortcode('[tag_count slug="test"] '); ?>

    with this php code?

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
      foreach($posttags as $tag) {
        echo $tag->slug . ' ';
      }
    }
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • You can do that, as long as you’re doing it inside the shortcodes function.

    You’d need to do something like this:

    function tag_count_shortcode ($atts, $content = '') {
        extract (shortcode_atts (array (
            "slug" => ""
        ), $atts);
    
        echo "<p>Slug is '" . $slug . "'</p>";
    }
    Thread Starter Alin Ionut

    (@c3dry2k)

    not to god on php, sry, I need the exact code ore codes.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Then have you contacted your theme’s or plugin’s author?

    Is it possible to replace “test” text from this shortcode with this php code?

    not directly, but you can include the ‘do_shortcode’ code into the foreach loop;

    example:

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
      foreach($posttags as $tag) {
        echo do_shortcode('[tag_count slug="' . $tag->slug .'"];
      }
    }
    ?>
    Thread Starter Alin Ionut

    (@c3dry2k)

    thank you, your code works, with one small mistake, you forgot ‘) to close.

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
      foreach($posttags as $tag) {
        echo do_shortcode('[tag_count slug="' . $tag->slug .'"]');
      }
    }
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PHP inside shortcode’ is closed to new replies.