我试图在WordPress中创建一个儿童主题。我通过将style.css
和function.php
添加到我的theme-child
目录中,但我的父母主题有css文件夹,其中包含样式单文件。从WordPress中加载样式表父母他们在
includes/css/main.css
includes/css/main.meanmenu
如何加载这些文件,在我的子主题中进行自定义?
我试图在WordPress中创建一个儿童主题。我通过将style.css
和function.php
添加到我的theme-child
目录中,但我的父母主题有css文件夹,其中包含样式单文件。从WordPress中加载样式表父母他们在
includes/css/main.css
includes/css/main.meanmenu
如何加载这些文件,在我的子主题中进行自定义?
通过检查下面的链接确认一次,到目前为止您创建的网站是否正确。它将描述子主题的创建
的子主题目录
1. style.css
2. functions.php
如果你已经完成了上述步骤。
您必须通过仪表板 - >外观 - >您的子主题 - >激活来选择子主题。
如果你想编辑:Appearence->编辑 - >的style.css(子)
这可能是你的问题一个错字,或与您的代码可能是一个错误,但你的问题声明您添加了一个function.php
文件,但它应该是functions.php
(带's')。
在您的child-theme/functions.php
文件中,您应该使用wp_enqueue_style()
加载样式表。
添加以下代码:
function xyz_enqueue_parent_css() {
wp_enqueue_style('parent-css-description-1', get_template_directory_uri() . '/includes/css/main.css');
// This filename seems incorrect, so change to suit needs
wp_enqueue_style('parent-css-description-2', get_template_directory_uri() . '/includes/css/main.meanmenu');
}
add_action('wp_enqueue_scripts', 'xyz_enqueue_parent_css');
的parent-css-description-1
和parent-css-description-2
可以是你想要的任何东西,但他们必须是唯一的。
假设您在主题中使用wp_head()
,这些CSS文件将由WordPress为您加载。
我如何确保有变化当我添加以前的代码 – user3680224
@ user3680224时发生当您查看网站的源代码时,应该会看到'
...'标签中列出的CSS文件。据推测,父主题CSS文件也会以一种明显的方式改变网站的外观。 –我看起来像href = http:// localhost:8080/project/website/wp-content/themes/parent-theme-name/includes/css/main.css“ – user3680224
我这样做就像你说的,但是当我去WordPress的编辑器style.css并键入css代码它不会在我的网站做任何改变 – user3680224
是我激活了我的孩子主题 – user3680224