Parent-Child theme question

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #22082
    Ixinho
    Participant

    Hello

    i already did quite a lot modifications to php files of the theme, without having child theme.
    Is it possible somehow that i create child theme now with all the modifications done, so next time i update your theme i dont lose any of these modifications?

    #22107
    Veena
    Moderator

    The theme bundle comes with child theme , You just need to import the same just like a normal theme and activate the same .
    You will get to know all the details of child theme here –
    https://codex.wordpress.org/Child_Themes

    #22108
    Ixinho
    Participant

    I will try it in the afternoon. Once i import it, will it get all the current modifications from the parent theme or only the default ones?

    #22138
    Veena
    Moderator

    You need to copy all your modification(in parent theme files) to your child theme . Otherwise if you update the theme in future you ll lose all the modifications since all the old files will be replaced with new one .

    #22389
    Ixinho
    Participant

    Hello Phoenix, sorry for the late reply, i havent realised it.
    I’m about to implement child theme today. I already changed some things in some php files, and plugins as well.
    When i open child theme folder i see only this (look at the screenshot).

    So bacially what should i copy? all folders from parent to child like framework with all subfolders, languages, css? what about php files that are in the root of the parent?
    and what about wordpress default files that i’ve changed, for example locale.php?

    I have uploaded your default child theme not, but havent activated it yet cause i’m just not sure how to do this and i would really use some help cause i would like to have child “backup” from now on for every change i do, but i would like that this child theme applies every single change i’ve done on parent until now..
    Thank you very much in advance
    Nikola

    #22413
    Raghavendra
    Moderator

    You don’t need to copy the parent theme files unless it happens to be a template file like header.php, single.php etc. and these are located in the root folder of the theme. For all other PHP files which are located inside framework folder and its subfolders, you just override the function changed since we do a function_exists() check in the parent theme and will load the child theme function (modified) instead of the one in the parent.

    For example, if you have made a change in the file framework/functions/post-functions.php file at line number 53 to function mo_entry_author() –

    if (!function_exists('mo_entry_author')) {
    
        function mo_entry_author() {
    
            $prefix = '<i class="icon-user13"></i>';
    
            $author = '<span class="author vcard">' . $prefix . '<a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '" title="' . esc_attr(get_the_author_meta('display_name')) . '">' . get_the_author_meta('display_name') . '</a></span>';
            return $author;
        }
    }

    since the function_exists() check exists above, you just copy this function into child theme and define the same function in your child theme functions.php file ( no need to create another post-functions.php file unless your changes are massive and you want to organize it that way). This child theme function will have the modified code. So, if you want to get rid of link to author, you would just have this function in your child theme functions.php file –

    if (!function_exists('mo_entry_author')) {
    
        function mo_entry_author() {
    
            $prefix = '<i class="icon-user13"></i>';
    
            $author = '<span class="author vcard">' . $prefix . get_the_author_meta('display_name') . '</span>';
            return $author;
        }
    }

    You should never modify wordpress default files like locale.php and should rely on either wp-config.php file or the wordpress admin settings or other admin pages to configure your installation.

    Hope this helps.

    #22415
    Raghavendra
    Moderator

    More information –

    https://codex.wordpress.org/Child_Themes

    and by googling “child themes wordpress”.

    #22418
    Ixinho
    Participant

    Thank you for nice explanation meteorite.
    In locale.php i translated only days and months, i think it shouldn’t be a big issue?
    so, if i understand correctly, if i modified some php files which are found in root of the theme (header for example), i have to copy the file to root of the child as well, and for all the modifications done within framework folder, i have to copy only that modified part into functions.php file in child theme?
    Once i do that, i can activate child theme and keep working on it, and then, if any update messes anything, i can always revert to parent?

    #22453
    Raghavendra
    Moderator

    You are right – for framework folder changes, I hope you mean the modified function when you say modified part. The whole function that changed needs to be copied.

    #22454
    Ixinho
    Participant

    Thank you meteorite. Resolved.

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Parent-Child theme question’ is closed to new replies.