首先在短代码回调函数外部注册样式表,然后在短代码回调函数中将其排队。例如:-
function wpsoe_191512_avatar_shortcode_wp_enqueue_scripts() {
wp_register_style( \'get-avatar-style\', plugins_url( \'/css/style.css\' , __FILE__ ), array(), \'1.0.0\', all );
}
add_action( \'wp_enqueue_scripts\', \'brw_avatar_shortcode_wp_enqueue_scripts\' );
if ( function_exists( \'get_avatar\' ) ) {
function wpse_165754_user_avatar_shortcode ( $attributes ) {
global $current_user;
get_currentuserinfo();
extract(shortcode_atts(array(
"id" => $current_user->ID,
"size" => 32,
"default" => \'mystery\',
"alt" => \'\',
"class" => \'\',
),
$attributes, \'get_avatar\' ));
$get_avatar= get_avatar( $id, $size, $default, $alt );
wp_enqueue_style( \'get-avatar-style\' );
return \'<span class="get_avatar \'.$class.\'">\'.$get_avatar.\'</span>\';
}
add_shortcode (\'get_avatar\', \'wpse_165754_user_avatar_shortcode\');
}
以上就是一个例子。你可以用你的。谢谢