do_shortcode_tag

最后更新于:2021-11-26 08:49:20

apply_filters( ‘do_shortcode_tag’, string $output, string $tag, array|string $attr, array $m )

Filters the output created by a shortcode callback.

参数

$output

(string)
Shortcode output.

$tag

(string)
Shortcode name.

$attr

(array|string)
Shortcode attributes array or empty string.

$m

(array)
Regular expression match array.

源文件

文件: gc-includes/shortcodes.php

View on Trac

add_action( 'gc_enqueue_scripts', 'register_my_script');
function register_my_script(){
  gc_register_script('my-shortcode-js',$src, $dependency, $version, $inFooter);
}
add_filter( 'do_shortcode_tag','enqueue_my_script',10,3);
function enqueue_my_script($output, $tag, $attr){
  if('myShortcode' != $tag){ //make sure it is the right shortcode
    return $output;
  }
  if(!isset($attr['id'])){ //you can even check for specific attributes
    return $output;
  }
  gc_enqueue_script('my-shortcode-js'); //enqueue your script for printing
  return $output;
}