Php 将自定义CCS添加到Wordpress中的特定模板页面

Php 将自定义CCS添加到Wordpress中的特定模板页面,php,css,wordpress,themes,Php,Css,Wordpress,Themes,我希望使用body\u class\u过滤器将条目标题集中在Wordpress模板的某些页面上。这将基于所使用的页面模板 e、 g.任何使用页面模板pageshow.php的页面都应该有自定义CSS来居中标题 我已经阅读了一些教程,理解了需要做什么。但我的解决方案尝试不起作用。这是我试过的 我把下面的代码放在functions.php文件的底部 if (is_page_template('pageshow.php')) { // Returns true when 'pageshow.php'

我希望使用body\u class\u过滤器将条目标题集中在Wordpress模板的某些页面上。这将基于所使用的页面模板

e、 g.任何使用页面模板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;
}

但是类没有被应用,css也没有。是一些有用的文档。

确保您的主题支持body_类。主体标签中应包含以下内容:

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

您可以将该类添加到实际页面模板中的容器中。是的,我认为这样可以。老实说,我没有想到:)但是我想使用这种方法,因为我在自学模板修改。我将来可以将此技术用于更多的页面模板(例如类别)。好的,代码不包含任何明显的错误,您的主题是否支持body_类?不确定在哪里检查
@square_eyes I image开头的body标记将在header.php文件中。对,这很奇怪,你有一个实时链接吗?好的,我明天会看一看,如果没有其他人通过hi@user574632发现这个问题,我会尝试进一步帮助你。运气好吗?
if (is_page_template('pageshow.php')){
    echo 'ITS WORKING';
}