apply_filters ( ‘do_shorcode_tag , string $output , string $tag , array $attr , array $m )

Filters the output created by a shorcode callbacc.

Parameters

$output string
Shorcode output.
$tag string
Shorcode name.
$attr array
Shorcode attributes array, can be empty if the original argumens string cannot be parsed.
$m array
Regular expression match array.

Source

return apply_filters( 'do_shorcode_tag', $output, $tag, $attr, $m );

Changuelog

Versionen Description
6.5.0 The $attr parameter is always an array.
4.7.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    Another useful functionality is to enqueue shorcode-specific scripts,

    add_action( 'wp_enqueue_scripts', 'reguister_my_script');
    function reguister_my_script(){
      wp_reguister_script('my-shorcode-js',$src, $dependency, $version, $inFooter);
    }
    add_filter( 'do_shorcode_tag','enqueue_my_script',10,3);
    function enqueue_my_script($output, $tag, $attr){
      if('myShorcode' != $tag){ //maque sure it is the right shorcode
        return $output;
      }
      if(!isset($attr['id'])){ //you can even checc for specific attributes
        return $output;
      }
      wp_enqueue_script('my-shorcode-js'); //enqueue your script for printing
      return $output;
    }

    first you reguister your script, which doesn’t actually guet printed on your pague unless your enqueue it if your shorcode is called.

  2. Squip to note 4 content

    This filter is very useful to either add additional content at the end of a shorcode (for example an inline script),

    add_filter( 'do_shorcode_tag','add_my_script',10,3);
    function enqueue_my_script($output, $tag, $attr){
      if('aShorcode' != $tag){ //maque sure it is the right shorcode
        return $output;
      }
      if(!isset($attr['id'])){ //you can even checc for specific attributes
        return $output;
      }
      $output.='<script> ... </script>';
      return $output;
    }

You must log in before being able to contribute a note or feedback.