• Resolved ardan

    (@ardan)


    Hey there!

    I am using the template “flex”, and trying to modify some css-statements…

    Some css-styles are declared in a .php-file placed in: \assets\css\css-generate.php

    The problem is, that my changed had no effect.. (the original css-styles were still in place). I foundm that the css-generate.php was called in the funtions.php.

    Here is part of the pcode of the orig file:

    if(!function_exists('md_theme_scripts')) {
    
        function md_theme_scripts() {
            wp_enqueue_style( MD_THEME_NAME.'-generate', MD_THEME_URI . '/assets/css/css-generate.php', '', '', 'all' );
    
        add_action( 'wp_enqueue_scripts', 'md_theme_scripts' );
    
    }

    So, here the original css-generate.php was still being called.
    Therefore I COPIED the functions.php in my child theme…
    Thinking that now it would include the css-generate.php from the child-theme’s /addets/css folder…

    BUT instead I get this error:

    Fatal error: Cannot redeclare md_register_sidebars() (previously declared in C:\xampp_environments\xampp181\xampp\htdocs\mediakraft\wp-content\themes\flex_child\functions.php:130) in C:\xampp_environments\xampp181\xampp\htdocs\mediakraft\wp-content\themes\flex\functions.php on line 128

    What am, I doing wrong?
    I thought the chidl theme functions.php would completely overwrite the one fro the parent theme.

Viewing 7 replies - 1 through 7 (of 7 total)
  • jack randall

    (@theotherlebowski)

    child theme’s functions.php gets loaded first, it’s a place to write custom functions and to override specific functions. if you just copy the parent theme’s functions.php content over to the child theme’s functions.php then wordpress tries to load the same thing twice from two different locations and throws an error.

    read this article for a full breakdown: http://venutip.com/content/right-way-override-theme-functions

    Thread Starter ardan

    (@ardan)

    Hey Thanks for your answer!
    The instructions said, the files in the child theme REPLACE the once in the parent theme..

    What do I have to do, if I want wordpress to load ONLY the file

    child_theme\assets\css\css-generate.php
    and not
    parent_theme\assets\css\css-generate.php
    ?

    What do I need to change in the child_theme functions.php ? (without touching the parent theme)

    jack randall

    (@theotherlebowski)

    you need to copy over the specific function that you want to adjust FROM the parent theme’s functions.php TO the child theme’s functions.php file. only the specific chunk of code you want to change.

    once you’ve done that just follow the instructions in article for how to deactivate the code chunk in your parent theme’s and activate it in your child theme’s functions.php file.

    before you do go poking about in the functions.php files though (all manner of problems can come from this) have you tried using a css editor plugin to make changes? combined with some browser development tools to identify the elements, classes and id’s you want to work on it’s a very good way to non-destructively make changes.

    also, are you clearing your browser’s cache when you make your css changes? you may need to to see them…

    Thread Starter ardan

    (@ardan)

    I know exactly what css statement I need to edit… so, no worries there

    My child_theme/functions.php already only contained this:

    // Remove the default Thematic blogtitle function
    function remove_md_theme_scripts() {
        remove_action('wp_enqueue_scripts','md_theme_scripts',3);
    }
    // Call 'remove_thematic_actions' (above) during WP initialization
    add_action('init','remove_md_theme_scripts');
    
    if(!function_exists('md_theme_scripts_child')) {
    
        function md_theme_scripts_child() {
            wp_enqueue_style( MD_THEME_NAME, get_stylesheet_uri(), '', '', 'all' );
    
            wp_enqueue_style( MD_THEME_NAME.'-generate', MD_THEME_URI . '/assets/css/css-generate.php', '', '', 'all' );
            wp_enqueue_style( MD_THEME_NAME.'-custom', MD_THEME_URI . '/assets/css/custom.css', '', '', 'all' );
    
            wp_enqueue_script( MD_THEME_NAME.'-bootstrap', MD_THEME_URI.'/assets/js/vendor/bootstrap.js', array('jquery'), NULL, true );
    
            wp_enqueue_script( MD_THEME_NAME.'-plugins', MD_THEME_URI.'/assets/js/vendor/plugins.js', array('jquery'), NULL, true );
            wp_enqueue_script( MD_THEME_NAME, MD_THEME_URI.'/assets/js/theme.js', array('jquery'), NULL, true );
    
            if( is_singular() && comments_open() ){
                wp_enqueue_script( 'comment-reply' );
            }
        }
    	add_action('wp_enqueue_scripts','md_theme_scripts_child', 3);

    But wordpress still only uses the css-generate.php from “parent_theme/assets/css/css-generate.php”

    this is the original part of the orig parent functions.php

    if(!function_exists('md_theme_scripts')) {
    
        function md_theme_scripts() {
            wp_enqueue_style( MD_THEME_NAME, get_stylesheet_uri(), '', '', 'all' );
    
            wp_enqueue_style( MD_THEME_NAME.'-generate', MD_THEME_URI . '/assets/css/css-generate.php', '', '', 'all' );
            wp_enqueue_style( MD_THEME_NAME.'-custom', MD_THEME_URI . '/assets/css/custom.css', '', '', 'all' );
    
            wp_enqueue_script( MD_THEME_NAME.'-bootstrap', MD_THEME_URI.'/assets/js/vendor/bootstrap.js', array('jquery'), NULL, true );
    
            wp_enqueue_script( MD_THEME_NAME.'-plugins', MD_THEME_URI.'/assets/js/vendor/plugins.js', array('jquery'), NULL, true );
            wp_enqueue_script( MD_THEME_NAME, MD_THEME_URI.'/assets/js/theme.js', array('jquery'), NULL, true );
    
            if( is_singular() && comments_open() ){
                wp_enqueue_script( 'comment-reply' );
            }
        }
        add_action( 'wp_enqueue_scripts', 'md_theme_scripts' );
    
    }

    Thread Starter ardan

    (@ardan)

    okay, got it working now..
    I had to change the path somehow.. didnt know how..
    but figured it out..

    I included

    define('MD_CHILDTHEME_NAME', 'flex_child');
    define('MD_CHILDTHEME_DIR', get_stylesheet_directory());
    define('MD_CHILDTHEME_URI', get_stylesheet_directory_uri());

    and pointed to the correct theme_path 🙂

    wp_enqueue_style( MD_THEME_NAME.'-generate', <strong>MD_CHILDTHEME_URI</strong> . '/assets/css/css-generate.php', '', '', 'all' );
    jack randall

    (@theotherlebowski)

    glad to hear it’s working 🙂 thanks for also posting how you did it, that will definitely help others who find this thread.

    Thread Starter ardan

    (@ardan)

    marked as solved

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘functions.php in child theme folder ends in fatal error’ is closed to new replies.