简体   繁体   中英

WordPress child-theme not formatting

I'm aware that people have had similar issues, but reading through questions here on stackoverflow, and on WP Codex, has not helped me to solve this issue. This is the second child theme I've made. The first one worked perfectly. For some reason, even though I did everything the same, this one does not reflect the formatting of the parent theme. My suspicion is that I either need to enqueue multiple .css for this particular theme, or I have an incorrect tag. Hoping that a new set of eyes could find the problem.

Here is the style.css for the child theme:

/*
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
*/

And here is the functions.php for the child theme:

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

As you can see, I have followed the directions from the WP Codex - CT .

This is what the formatting is supposed to look like.

UPDATE: I have now got my child theme looking like the parent theme by copy/pasting all the content from the parent style.css to the child. However, doesn't this defeat the purpose of enqueue? If I have the parent and child enqueued correctly, shouldn't the formatting from the parent reflect in the child theme?

Try this in your child theme's functions file. It seemed to do the trick for me.

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

In case someone else lands here, this has been fixed at:

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

Heres a gist of the code that needs to be in functions.php in the child theme:

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

I can confirm that this gist works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM