0

Hi I troubling with creating a working child-theme. I tried following the codex.wordpress and adjusted everything like below. But when I then activate the child theme in wordpress, the website is not working anymore and just white.

Do you see a mistake somewhere here? Thank you very much in advance!

enter image description here

style.css of the child

/*
Theme Name: flatsome-child-newest
Description: This is a child theme for Flatsome Theme
Author: UX Themes
Template: flatsome-newest
Version: 3.0
*/

functions.php of the child

<?php
// Enqueue stylesheets and dependencies

$parent_style = 'flatsome-style';

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}

function my_theme_enqueue_styles() {

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


**and some custom code**
3
  • does the 'flatsome-newest' folder contain a parent theme? have you tried to enable DEBUG codex.wordpress.org/Debugging_in_WordPress to see if you get error messages? what exact is in this 'and some custom code'? PS: i just see you are using the same function name twie - 'my_theme_enqueue_styles()' which is most likely the cause of the problem. – Michael Jun 23 '17 at 1:46
  • Are you sure that on this line: Template: flatsome-newest you have the name of the parent theme, not the name of its directory? – cjbj Jun 23 '17 at 8:24
  • I think @cjbj is right, try using Template: flatsome instead if you not already tried that. Also as you are having multiple folders of the flatsome theme, make sure that they dont have the same theme name inside the style.css files. – LWS-Mo Jun 23 '17 at 13:48
1

I always find it best to start simple, make something that works, then build another tiny piece. That way it's easier to determine at what point something is going wrong.

I would suggest removing everything except the parent "flatsome" theme from your server. (Keep your backups locally, just don't have them installed in WP.)

Next, create a new theme folder "flatsome-wpse" with only a "style.css" file. (I suspect one of your issues is the "template" is wrong - "template" should be the folder name of the parent theme, which in your case is just "flastome"):

/*
Theme Name: WPSE Flatsome
Description: Child theme from scratch
Author: UX Themes
Template: flatsome
Version: 1.0
*/

With just that folder and file uploaded, see if you can activate the theme. If so, you should simply see the parent theme in action with no overrides. Then, proceed with customizations - add some specific CSS that makes it easy to visually see whether the child theme is overriding or not, like perhaps a body background.

Also of note, your "functions.php" file does not need to enqueue the parent stylesheet. This should be done by the parent theme already. You are trying to enqueue the parent style twice, so in addition to the parent enqueueing itself, you're calling the parent stylesheet 3 times. And, you can use get_stylesheet_uri to pull in your child theme's style.css file. So, all you need to do is enqueue your child theme's custom styles:

<?php
add_action('wp_enqueue_scripts', 'wpse_flatsome_enqueue_styles', 20);
function wpse_flatsome_enqueue_styles() {
    wp_enqueue_style( 'flatsome-wpse-style',
        get_stylesheet_uri(),
        array( 'flatsome-style' ),
        wp_get_theme()->get('Version')
    );
}
?>

Once you can visually verify that your child theme's styles are working, you can add the additional functions.php code and any other overrides you want to add. Again, one small step at a time, so you can tell exactly which step causes issues, which makes it much faster to troubleshoot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.