WordPress Hook动作钩子 template_redirect
Wordpress Hook动作钩子 template_redirect 是确认用户正在浏览的页面的关键,用于在特定页面选择 theme template 之前执行。
调用方法:
add_action( 'template_redirect', 'function_name' );
比如在特定页面加载一个特定的样式表。
<?php
add_action( 'template_redirect', 'author_css' );
function author_css(){
if( is_singular( 'post' ) ){
wp_enqueue_style (
'author-post',
'author-example.css',
false,
0.1,
'screen'
);
}
}
?>