wordpress儿童主题functions.php

时间:2016-10-22 17:26:20

标签: php wordpress themes

我正在尝试创建一个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文件中我必须进行哪些修改,即在哪里可以将我的主题名称放在功能中?

谢谢,

纳温

2 个答案:

答案 0 :(得分:0)

添加actionfilter个钩子可以通过 functions.php

完成

请在 functions.php

中添加wp_enqueue_scripts代码

答案 1 :(得分:0)

首先您需要了解子主题的实际工作方式。子主题使用其父主题的文件,并为子主题生成另一个style.css。通常,人们为设计定制开发新的子主题。现在,如果您想添加其他功能或更改默认功能,则需要将其添加到functions.php。

在此代码中,您将添加父主题的style.css文件以及子主题。

如果您仍然遇到问题,可以使用插件创建子主题。

https://wordpress.org/plugins/one-click-child-theme/

安装插件,现在您只需要选择新主题和新子主题的名称,就可以了。

相关问题