0

Fairly new to wordpress and coding but followed these guidelinen in order to create a child theme and enqueue the parent css as well as the child css:

https://codex.wordpress.org/Child_Themes https://siteorigin.com/basics/child-themes/

child theme folder is directly under wp-content/themes and has the name vantage-child. In that folder I have functions.php and style.css

style.css code:

/*
Theme Name: Vantage Child
Author: SiteOrigin
Author URI: [can't post link because I don't have 10 reputations]
Theme URI: [can't post link because I don't have 10 reputations]
Description: Vantage Child Theme
Version: 1.0.0
Template: vantage
Text Domain: vantage-child
*/

the functions.php in the child-theme folder has the following code:

<?php
function my_theme_enqueue_styles() {

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

?>

The thing I am not sure about is the variable $parent_style. I find the one I used in the functions.php in the parent folder, however the sitorigin guideline said vantage-parent-style. Tried both, didn't work. Also checked the permissions of the files but those are all '644' equal to the other files in the wordpress folders...

Hope someone can help!

4
  • $Parent_style - exactly the unique name?
    – TrubinE
    Mar 20, 2017 at 21:53
  • I think so! Got it from this part of the functions.php of the parent: function vantage_scripts() { wp_enqueue_style( 'vantage-style', get_stylesheet_uri(), array(), SITEORIGIN_THEME_VERSION );
    – bastiaan
    Mar 20, 2017 at 22:19
  • Try to replace with:` $parent_style = 'vantage-style-custom';`
    – TrubinE
    Mar 20, 2017 at 22:21
  • Followed your suggestions and left everything the samen. Unfortunately no result. Maybe any other suggestions?
    – bastiaan
    Mar 20, 2017 at 22:26

1 Answer 1

0

Assuming the parent theme properly enqueues it's style.css, there is no need for your child them to also enqueue it. As follows:

parent themes's functions.php

add_action ('wp_enqueue_scripts', 'parent_enqueue_scripts_styles') ;

function
parent_enqueue_scripts_styles ()
{
    wp_enqueue_style ('parent_style', get_template_directory_uri () . '/style.css') ;

    return ;
}

child themes's functions.php

add_action ('wp_enqueue_scripts', 'child_enqueue_scripts_styles') ;

function
child_enqueue_scripts_styles ()
{
    wp_enqueue_style ('child_style', get_stylesheet_directory_uri () . '/style.css') ;

    return ;
}

and you'll get an HTML <head> as follows:

<html>
    <head>
        ...
        <link rel='stylesheet' id='parent_style-css' href='path_to_parent_theme/style.css' type='text/css' media='all'>
        ...
        <link rel='stylesheet' id='child_style-css' href='path_to_child_theme/style.css' type='text/css' media='all'>
        ...
    </head>
    ...
</html>
5
  • Thanks for the reply! I used your code of the child theme's functions.php and copy pasted. Left the functions.php of the parent the same (as it is already working and the css is being called there like your said). Still there is no 'extra' theme showing up in my backend...
    – bastiaan
    Mar 20, 2017 at 22:23
  • No unfortunately not. As said in all the guidelines I encountered I have to activate the child theme in my backend, but it doesn't show up there. Have no clue what to try now...
    – bastiaan
    Mar 20, 2017 at 22:39
  • sorry, I missed the main point of your question, my bad. Try the following: remove the Template: header comment in your child theme's style.css and see if you can see it in the Appearance > Themes menu. If you still can't see it after that change, then whatever the problem is has nothing to do with it being a child them. Mar 20, 2017 at 23:24
  • Also, are you trying to active this child theme in a multisite or "normal" WP install? If it is multisite, then you need to go to Network Admin > Sites, edit the site in question, go to the Themes tab and "enable" your child theme. Then, go back to the dashboard for your site and your child theme should show up in Appearance > Themes. Mar 20, 2017 at 23:27
  • Oke the strangest thing happened. I woke up this morning and the folder wp-content/theme/vantage-child was gone! I am quite certain that I didn't misplace the folder and also looked under other possible folders. So strange! Anyways, recreating the folder structure and files of course was easy. And with the exact code you posted the theme was visible in the backend. Really have no clue what made my folder disappear (cron job, auto script or ?). anyways I can continue my journey in wordpress :) Thank you all!
    – bastiaan
    Mar 21, 2017 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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