1 回答

TA貢獻1895條經驗 獲得超7個贊
如果您想嚴格使用 JS 執行此操作,則可以在子主題的 script.js 文件中使用以下內容:
if(document.body.classList.contains('blog')){
? ? Array.from(document.querySelectorAll('header#header>div')).forEach((item, index) => {
? ? ? ? if(index > 0){
? ? ? ? ? ? item.classList.add('hide');
? ? ? ? }
? ? });
}
在您的子主題的 functions.php 文件中,您可以添加它以將您的 script.js 包含在您的主題中。
function mytheme_child_enqueue_scripts () {
? ? wp_enqueue_script('script-js', get_stylesheet_directory_uri().'/script.js', '', null, true);
}
add_action('wp_enqueue_scripts', 'mytheme_child_enqueue_scripts');
如果您使用 JavaScript 執行此操作,請確保滿足以下三個先決條件:
不要
.hide
在 PHP 中添加類。如果未在 PHP 中添加,請驗證正確的標題項是否已
.hide
通過script.js
.使用在 CSS 中定位它
header#header .hide { display: none; }
如果 JS 不是實現此目標的嚴格要求,盡管要使其適應您對博客頁面的要求,請使用它來實現您想要做的事情:
body.blog #header [data-row=middle],
body.blog #header [data-row=bottom] {
? ? display:none
}
- 1 回答
- 0 關注
- 116 瀏覽
添加回答
舉報