在我的Wordpress主题中,我使用自定义模板的自定义帖子类型很少。这些模板使用其他数据,如特定的CSS或Java Script。
有没有办法将这种数据附加到get_header()函数,所以我可以改变它而不在我的自定义帖子类型模板中硬复制它?
简而言之,例如。插入
<link rel="stylesheet" href="<?php echo get_bloginfo('template_url'); ?>/css/interview.css" type="text/css" media="all">
内部
get_header();
答案 0 :(得分:0)
如果我正确理解了这个问题,那么你需要这样的东西: -
function theme_name_scripts() {
global $post;
$post_type = get_post_type( $post );
if( $post_type === 'your-custom-post-type-slug-here' ) { // edit this line as per requirements
wp_enqueue_style( 'style-interview', get_bloginfo('template_url') . '/css/interview.css' );
}
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
(感谢@TopDown提供评论中的效果提示。)
您只需将上述代码放在主题的Functions.php中即可。有关详细信息:http://codex.wordpress.org/Function_Reference/wp_enqueue_style