我有一个特定分类法的模板:
taxonomy-mytaxonomy.php
<?php
defined( \'ABSPATH\' ) || exit;
get_header( );
?>
<!-- Content -->
<div id="content" class="content" role="main">
<?php
the_archive_description( \'<div class="taxonomy-description">\', \'</div>\' );
if ( have_posts() ) {
$queried_object = get_queried_object();
$term_slug = $queried_object->slug;
$shortcode = sprintf( \'[my-shortcode attr1="value1" /]\',
$term_slug
);
echo do_shortcode($shortcode);
} else {
get_template_part( \'no-results\', \'search\' );
}
?>
</div><!-- #content -->
<?php get_footer(); ?>
在另一个php文件中,我需要检查do\\u shortcode是否将与一起运行my-shortcode
标记以将样式和脚本排队。public function check_page(){
global $post;
if( !empty( $post->post_content ) && has_shortcode( $post->post_content, \'my-shortcode\' ) ){
add_action( "wp_enqueue_scripts", array( $this, "set_scripts" ) );
}
}
就我而言,我不能使用has_shortcode( $post->post_content, \'my-shortcode\' )
因为它不在post_content
但直接在模板php文件中。Soemone有主意了?