1

I'm starting a new Wordpress website, so thought I'd start by creating a child theme. I've created the themename-child directory, and added the style.css and functions.php files within this directory.

I've entered the basic code required in these 2 files. However, when I activate the child theme and then view my website, the actual PHP code from the functions.php file is visible at the top of my website.

I'd really appreciate any assistance on why this code is visible on my site. I have checked and ensured every dot and space is identical to the code advised on this website: https://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme

This is the code in my functions.php file:

<?php 

function my_theme_enqueue_styles() {      
    $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.      
    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' ); 
?>

Many thanks for your patience and assistance.

Angela

  • 1
    Make sure if your php code in file is enclosed in <?php ?>. And you actually don't need to add functions.php file in your child theme folder until you don't want to add additional function that are not available in your parent theme's functions.php. – Rishabh Sep 21 '16 at 7:35
  • Thanks for your reply. All the code is enclosed in the php brackets. ie. the function starts with <?php and ends with ?> The code has been copied, character for character, from the codex.wordpress.org link in my original post. – Ange_S Sep 21 '16 at 9:14
  • In that case it would be better if you show whole code of functions.php file in your question so that we come to know why your code is showing up in webpage. – Rishabh Sep 21 '16 at 9:25
  • I've updated the original post with the functions.php code - thanks for your help. – Ange_S Sep 21 '16 at 11:58
  • Your functions appears to be okay. Can you show us exactly what is appearing at the top of your page? And do you have debuggin on? – ngearing Sep 22 '16 at 4:39
1

What you miss is that in your code snippet above you failed to name your own parent style.

In the code, you posted in the 4th line from above need customization according to the name of your actual parent style. So as an example this line:

 $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.

should look like this in case of using Divi:

 $parent_style = 'divi-style'; // This is 'divi-style' for the Divi theme.

To find out what you should put there instead of parent-style in your case, go to your parent theme folder and open the original (or now parent) functions.php, and there search for wp_enqueue_style.

You will find something like this:

wp_enqueue_style( 'divi-style', get_stylesheet_uri(), array(), $theme_version );

This is in my case where I use Divi theme. Look at the first attribute of the function. That's what you need.

The other example: In case Twenty Fifteen the first attribute will be twentyfifteen-style.

So once you found the used tag-name for your parent style update your 4th line accordingly.

| improve this answer | |

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.