【问题标题】:wordpress child theme functions.phpwordpress子主题functions.php
【发布时间】:2017-03-04 20:20:57
【问题描述】:

我正在尝试创建一个 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 文件中的什么地方进行修改,即我应该将我的主题名称放在功能中的什么位置?

谢谢,

纳温

【问题讨论】:

    标签: php wordpress themes


    【解决方案1】:

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

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

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

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

    安装插件,现在您只需选择父主题和新子主题的名称即可。

    【讨论】:

      【解决方案2】:

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

      请在functions.php中添加wp_enqueue_scripts代码

      【讨论】:

        猜你喜欢
        • 2018-03-24
        • 2017-01-16
        • 2013-07-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-11
        • 1970-01-01
        相关资源
        最近更新 更多