首页 > 解决方案 > 无法创建 Wordpress 子主题

问题描述

因此,我正在尝试从 wordpress 主题“全屏代理”创建一个名为 Premierpas 的子主题。我在主题中创建了 Premierpas 文件夹,然后添加了一个包含该内容的 css 文件:

/*
 Theme Name:   Premier Pas
 Author:       Garga Le Noir
 Template:     fullscreen-agency
 Version:      1.0.0
*/

和具有此内容的functions.php:

<?php
function premierpas_enqueue_styles() {

    $parent_style = 'fullscreen-agency';

    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 ),null);
}

我已经尝试了很多其他版本的函数代码,但都没有成功。当我尝试激活它时,我的网站就崩溃了。我只有一条消息告诉我存在技术问题,我收到一封电子邮件以激活恢复模式。我确信这个错误是微不足道的,如果我在浪费你的时间,我很抱歉,但我很坚持这个......任何帮助将不胜感激,在此先感谢

标签: phpwordpresschild-theming

解决方案


我用你上面提到的代码创建了一个子主题,它对我有用。我所做的一项更改是我将父级设置为,twentyfifteen因为我没有您的fullscreen-agency父级主题。我假设你的文件路径是......

wp-content/themes/premierpas/style.css
wp-content/themes/premierpas/functions.php

有几件事要尝试...

  1. 删除您的 functions.php 文件。如果这样可以解决问题,那么您可能已经premierpas_enqueue_styles()在父主题中定义了或者存在一些相关的错误。
  2. 通过将以下内容添加到您的 wp-config.php 文件来启用 debug.log...define( 'WP_DEBUG', true );然后尝试重新激活子主题并查看您的 wp-content/debug.log 文件以查看是否有任何相关错误可以提供帮助您进一步排除故障。

推荐阅读