【发布时间】:2021-12-29 04:18:15
【问题描述】:
add_action( 'wp_head', 'betterdocs_customize_css');
如何让它在我指定的页面上运行,而不是在所有内部页面上运行? 由于我将它添加到标题部分,css 出现在所有不必要的页面上。我只希望它在一页上,我该如何过滤它? 例如;只需将其添加到 domain.com/documents 页面的标题中即可。
【问题讨论】:
add_action( 'wp_head', 'betterdocs_customize_css');
如何让它在我指定的页面上运行,而不是在所有内部页面上运行? 由于我将它添加到标题部分,css 出现在所有不必要的页面上。我只希望它在一页上,我该如何过滤它? 例如;只需将其添加到 domain.com/documents 页面的标题中即可。
【问题讨论】:
你可以这样添加,
add_action('wp_head','betterdocs_customize_css');
function betterdocs_customize_css(){
//check for the current page is your targeted page by id
if( is_page( 42 ) ){
echo "<style> your style here </style>";
}
}
通过这样做,您可以在标题中仅打印目标页面的样式。
【讨论】: