wordpress 子主题 functions.php
wordpress child theme functions.php
我正在尝试创建一个 Wordpress 子主题并且一直在访问以下网站:https://codex.wordpress.org/Child_Themes。
在这个网站上它说我必须创建两个文件,其中 style.css 很清楚,我的问题是关于 functions.php。它说在某些时候我必须在新创建的 functions.php 文件中复制粘贴以下文本:
<?php
function my_theme_enqueue_styles() {
$parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
我想知道我必须在这个 php 文件中的什么地方进行修改,即我应该在功能中的什么地方放置我的主题名称?
谢谢,
纳文
添加 action
或 filter
挂钩可以通过 functions.php
完成
请在functions.php
中添加wp_enqueue_scripts
代码
首先您需要了解子主题的实际工作原理。子主题使用其父主题的文件,并为子主题生成另一个style.css。通常,人们会开发一个新的子主题来进行设计定制。现在,如果您想添加其他功能或更改默认功能,您需要将其添加到 functions.php.
在此代码中,您要添加父主题和子主题的 style.css 文件。
如果您仍然遇到问题,可以使用一个插件来创建子主题。
https://wordpress.org/plugins/one-click-child-theme/
安装插件,现在您只需要 select 父主题和新子主题的名称就可以了。
我正在尝试创建一个 Wordpress 子主题并且一直在访问以下网站:https://codex.wordpress.org/Child_Themes。
在这个网站上它说我必须创建两个文件,其中 style.css 很清楚,我的问题是关于 functions.php。它说在某些时候我必须在新创建的 functions.php 文件中复制粘贴以下文本:
<?php
function my_theme_enqueue_styles() {
$parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
我想知道我必须在这个 php 文件中的什么地方进行修改,即我应该在功能中的什么地方放置我的主题名称?
谢谢,
纳文
添加 action
或 filter
挂钩可以通过 functions.php
请在functions.php
中添加wp_enqueue_scripts
代码
首先您需要了解子主题的实际工作原理。子主题使用其父主题的文件,并为子主题生成另一个style.css。通常,人们会开发一个新的子主题来进行设计定制。现在,如果您想添加其他功能或更改默认功能,您需要将其添加到 functions.php.
在此代码中,您要添加父主题和子主题的 style.css 文件。
如果您仍然遇到问题,可以使用一个插件来创建子主题。
https://wordpress.org/plugins/one-click-child-theme/
安装插件,现在您只需要 select 父主题和新子主题的名称就可以了。