• Quick question about adding code to functions.php in my child theme. When I created my child theme instead of doing @import, I added functions.php in FTP and put the following code in there.

    <?php
    function theme_enqueue_styles() {

    $parent_style = ‘parent-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 )
    );
    }
    add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );

    Which from my understanding is the same thing as @import but is the better option now for speed of my website.

    Now, I have tried adding new code below this in that functions.php in my child theme and it makes my site go blank. I understand functions.php is the one place where you can’t modify the same file that is in the parent. I’ve looked all over and haven’t found a clear answer. So Should I create a new functions.php file and name it something different on top of the original functions.php. So I would have TWO functions.php files, but one could be called for example functions-child.php. And then I would be able to add functions to it??? And would that be completely different from just adding code to the original functions.php. Because in the end I just want to modify the functions of the website, but I’m wondering if that second file would interfere with the first????

    Thank You for any explanations

Viewing 5 replies - 1 through 5 (of 5 total)
  • You shouldn’t need to have more than one functions.php in your child theme. What code did you add? Can you post the contents of your child theme’s functions.php, including the code you tried to add that caused the site to go blank, to Pastebin and post the link here?

    Thread Starter mcubed1111

    (@mcubed1111)

    <?php
    function theme_enqueue_styles() {

    $parent_style = ‘parent-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 )
    );
    }
    add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );

    ^That is what is in my functions.php right now….The code I tried to add was for a sidebar, I deleted it though….cause I realized I can’t just add that to functions.php or that will mess with the existing code.

    How did you try to add the additional sidebar? Can you post the contents of your child theme’s functions.php, including the code you tried to add that caused the site to go blank, to Pastebin and post the link here?

    Thread Starter mcubed1111

    (@mcubed1111)

    I don’t have it…unfortunately. I was trying to follow a tutorial on a website. And the code in my last post is what is in my child functions.php right now. So I realize I can’t add anymore code onto the functions.php in my child unless I reformat that code.

    Can you post a link to the tutorial you followed? There’s no reason why you shouldn’t be able to add more code to your child theme’s functions.php, unless there was an error in the code you were trying to add.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Functions.php in child theme’ is closed to new replies.