【问题标题】:WordPress child-theme not formattingWordPress子主题未格式化
【发布时间】:2017-03-14 18:36:27
【问题描述】:

我知道人们也遇到过类似的问题,但通读 stackoverflow 和 WP Codex 上的问题并没有帮助我解决这个问题。 这是我制作的第二个儿童主题。第一个工作完美。出于某种原因,即使我所做的一切都是一样的,但这并不能反映父主题的格式。我的怀疑是我要么需要为这个特定主题排队多个 .css,要么我有一个不正确的标签。 希望新的眼睛能发现问题。

这是子主题的 style.css:

/*
Theme Name: Kale-child
Theme URI: https://panaceats.com/
Author: ****
Author URI: https://panaceats.com/
Description: child theme of Kale
Template: kale
Version: 1.0.0
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.en.html
Text Domain: kale
Domain Path: /languages/
Tags: one-column, two-columns, three-columns, right-sidebar, grid-layout, flexible-header, custom-background, custom-colors, custom-header, custom-menu, featured-images,footer-widgets, full-width-template, theme-options, threaded-comments, translation-ready, food-and-drink
*/

这是子主题的functions.php:

<?php
function my_theme_enqueue_styles() {

$parent_style = 'kale-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' );
?>

如您所见,我已按照WP Codex - CT 的指示进行操作。

This 是格式应该是什么样子。

更新:我现在通过将父 style.css 中的所有内容复制/粘贴到子主题,使子主题看起来像父主题。但是,这不是违背了入队的目的吗?如果我正确地将父母和孩子排队,父母的格式不应该反映在孩子主题中吗?

【问题讨论】:

  • 在 header.php 中从头部添加样式,不要使用这个愚蠢的函数
  • “kale-style”是否与 Kale 主题在调用 style.css 时在其 functions.php 中使用的句柄相同?

标签: php css wordpress parent-child


【解决方案1】:

在您的子主题的函数文件中试试这个。它似乎对我有用。

<?php
	add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
	
	function enqueue_parent_styles() {

		   $deps = array('bootstrap', 'bootstrap-select', 'font-awesome', 'owl-carousel');
    		   wp_enqueue_style('kale-style', get_template_directory_uri() . '/style.css', $deps );


	
		}
	
?>

【讨论】:

    【解决方案2】:

    万一其他人降落在这里,这已被修复为:

    https://wordpress.org/support/topic/child-theme-style-diferent-from-parent-theme/

    以下是子主题的functions.php中需要的代码要点:

    https://gist.github.com/lyrathemes/7f5c791b7351b7cadd7ab9faaba0b204

    我可以确认这个要点对我有用。

    【讨论】:

      猜你喜欢
      • 2019-07-17
      • 1970-01-01
      • 1970-01-01
      • 2017-03-07
      • 2014-10-13
      • 1970-01-01
      • 2020-09-13
      • 1970-01-01
      • 2020-04-23
      相关资源
      最近更新 更多