WordPress子主题未显示

时间:2016-10-25 06:42:16

标签: php wordpress

我刚创建了一个子主题并将其激活。但是当我访问该页面时,它完全是空白的。

在显示中是主题文件夹,其中我有我的父主题和子项,然后下面是来自父style.css的网站详细信息,我只是将其复制并粘贴到子样式表。

enter image description here

functions.php看起来像这样:

<?php
function my_theme_enqueue_styles() {

    $parent_style = 'parent-style';

    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' );
?>

如图所示,主题处于活动状态。

enter image description here

如何创建子主题并将其显示为父主题?

2 个答案:

答案 0 :(得分:3)

您不应该只复制父样式,最好创建一个新样式并导入父样式。您还需要将模板指定为父主题。试试这个:

/*
    Theme Name:   Sidimaag Child Theme
    Theme URI:    http://underscores.me
    Description:  Sidimaag Child Theme
    Author:       mytheme
    Author URI:   http://mytheme.co.za
    Template:     sidimaag
    Version:      1.0.0
    License:      GNU General Public License v2 or later
    License URI:  http://www.gnu.org/licenses/gpl-2.0.html
    Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
    Text Domain:  sidimaag
    */

然后您可以使用@import导入父类的样式:

@import url('path_to_parent_theme/style.css');

答案 1 :(得分:0)

为了挽救你的生命,只需安装themify插件即可。 这很简单。您安装插件。去: 外观 - &gt;主题 当您看到主题时,将鼠标悬停在主题上,您将看到主题详细信息。单击它,然后查找名为的按钮:create child theme..name your theme,click ok ...和vuala !!!