• Hi, I’ve have custom css modifying the Twenty Fourteen theme on https://www.kimnovakartist.com since we first built it early last year. I’ve had it contained in the Jetpack Edit css module to preserve it through updates. This weekend we needed to add a function to functions.php to exclude all but one category from the Home page, so I thought I might as well go ahead and make a child theme so that would be preserved through updates as well. Followed the instructions I found in the WP Codex to create style.css and functions.php. Created a directory in Themes for it and uploaded the text files. Activated the child theme, and site immediately went downdue to a 500 internal server error. Is this because I still had the Edit css module of Jetpack activated, or is it for some other reason?
    Here’s my functions.php:

    (<?php)
    
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    
    }
    
    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' );
    
    //Exclude categories from Home.
    function exclude_category_home( $query ) {
    if ( $query->is_home ) {
    $query->set( 'cat', '-1, -234' );
    }
    return $query;
    }
    
    add_filter( 'pre_get_posts', 'exclude_category_home' );

    Custom css is a long file, but here’s the header:

    /*
     Theme Name:   Twenty Fourteen Child
     Theme URI:    https://www.kimnovakartist.com/twentyfourteen-child/
     Description:  Twenty Fourteen Child Theme, developed for www.kimnovakartist.com
     Author:       Hannah West Design
     Author URI:   https://www.hannahwestdesign.com
     Template:     twentyfourteen
     Version:      1.0.0
     License:      GNU General Public License v2 or later
     License URI:  https://www.gnu.org/licenses/gpl-2.0.html
     Tags:         dark, one-column, left-sidebar, responsive-layout
     Text Domain:  twentyfourteen-child
    */

    Not sure if I have included everything needed for someone to lend a hand, so let me know if there’s anything else you need. Naturally I have switched back to the Twenty Fourteen theme for now. Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You need to check your site’s error logs for a more informative error

    Thread Starter Hannah West Design

    (@vesica)

    This server error appeared several times in the sever error log, apparently for each time I tried to activate the child theme and instead got a 500 internal server error:

    20150628T135127: https://www.kimnovakartist.com/wp-admin/admin-ajax.php
    PHP Parse error: syntax error, unexpected ‘)’ in …/public_html/wp-content/themes/twentyfourteen-child/functions.php on line 1

    This appears to reference the opening of the functions.php file, which I created according to the instructions on this page of the WordPress Codex: https://codex.www.ads-software.com/Child_Themes as follows:

    (<?php)

    What should I do?

    Thread Starter Hannah West Design

    (@vesica)

    OK, I think I see now that the opening line php declaration in the Codex is written in brackets that should not be included in the file. I’m going to try removed the parens and see if activating the child theme works after that. I’ll let everyone know if this worked. I’m a newb when it comes to PHP code but learning bits and pieces here and there…

    Thread Starter Hannah West Design

    (@vesica)

    Activating the child theme resulted in a new error appearing 3 times in the log:

    20150629T110239: https://www.kimnovakartist.com/index.php
    PHP Fatal error: Cannot redeclare theme_enqueue_styles() (previously declared in …/public_html/wp-content/themes/twentyfourteen-child/functions.php:5) in /hermes/bosnaweb04a/b761/ipw.kimnovakartistcom/public_html/wp-content/themes/twentyfourteen-child/functions.php on line 18

    Looking at the code, I do see that the line
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); appears at the beginning AND the end of the enqueue code. In my file, that’s line 3 and line 18. This is the way it was presented in the Codex…but could that be in error? I do see a note that this only works if you have one stylesheet, which is all we have in this case. And looking again I see another note: “Your child theme’s stylesheet will usually be loaded automatically. If it is not, you will need to enqueue it as well. Setting ‘parent-style’ as a dependency will ensure that the child theme stylesheet loads after it.” So maybe I don’t even need that second block of code. I’ll try removing it and activate again…

    Thanks for your help.

    Thread Starter Hannah West Design

    (@vesica)

    Nope, that didn’t work. Again a new 500 internal server error:
    20150629T112721: https://www.kimnovakartist.com/wp-admin/themes.php
    PHP Fatal error: Cannot redeclare exclude_category_home() (previously declared in /hermes/bosnaweb04a/b761/ipw.kimnovakartistcom/public_html/wp-content/themes/twentyfourteen-child/functions.php:10) in /hermes/bosnaweb04a/b761/ipw.kimnovakartistcom/public_html/wp-content/themes/twentyfourteen/functions.php on line 527

    It looks to me like this is due to the fact that I had previously added the exclude categories code to the main Twenty Fourteen functions.php. Let’s see if removing it before activating the child theme works.

    Thread Starter Hannah West Design

    (@vesica)

    LIttle Happy Dance!! It worked! I had to resave my custom menu after activating, but my custom styles and category exclusions are all intact! I will quickly disable my Edit CSS custom styles to make sure it stays this way…Squeak!! Everything looks good! Thanks for helping me help myself, Andrew. It was the error log I needed, and your suggestion spurred me to dig harder for it since I couldn’t find it in the hosting account. Looks like I’m good to go now.

    Hi, I have to solve similar problem..
    After installing the theme, to edit it with the Child theme I did not consider to add anymore on style.css usuall @import but i added on functions.php the function:

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

    but nothing, just corrupt theme on WP control panel..
    Then i discovered i wrote on style.css file, Template: Tracks instead of Template: tracks with lowercase t , and no more corrupt theme.
    I activeted the child theme and.. 500 internal server error!!
    Anyway, now i fixed this problem reinstalling after deleting tabels on mySql.
    That is final, the function on functions.php, do i have to change something or this is the code??
    And if i have another css called style.min.css , what i have to do??
    Thanks!!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Activating child theme results in 500 Internal Server Error’ is closed to new replies.