gpt4 book ai didi

php - 将自定义 CSS 添加到 Wordpress 中的特定模板页面

转载 作者:行者123 更新时间:2023-11-28 11:48:32 25 4
gpt4 key购买 nike

我希望使用 body_class_filter 使 Wordpress 模板中某些页面的条目标题居中。这将基于所使用的页面模板。

例如任何使用页面模板 pageshow.php 的页面都应该有自定义 CSS 来使标题居中。

我已经阅读了一些教程并了解需要做什么。但我的解决方案尝试不起作用。这是我尝试过的...

我将以下内容放在我的 functions.php 文件的底部...

if (is_page_template('pageshow.php'))
{ // Returns true when 'pageshow.php' is being used.
function my_class_names($classes)
{ // add 'class-name' to the $classes array
$classes[] = 'pageshowclass';
return $classes; // return the $classes array
}

// Now add pageshowclass class to the filter

add_filter('body_class', 'my_class_names');
}
else
{ // Returns false when 'about.php' is not being used.
}

还有我样式表中的下面...

/* Custom Page Styling by ID */
.pageshowclass h1.entry-title {
text-align: center;
}

但是class没有应用,css也没有。 Here是一些有用的 doco。

最佳答案

确保您的主题支持 body_class。它的 body 标签中应包含以下内容:

<body <?php body_class(); ?>>

如果是,请检查您的 if 条件是否返回 true,例如:

if (is_page_template('pageshow.php')){
echo 'ITS WORKING';
}

关于php - 将自定义 CSS 添加到 Wordpress 中的特定模板页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20388022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com