• Resolved pezbonoba

    (@pezbonoba)


    I know there have been various questions like this before, and I have read many of the threads concering this issue, but I am yet to understand what is considered best practice.

    I use a child theme. I want to make som changes in the code. What is the best way to do it? I have understood that there are mainly three ways.

    1. Copy entire parent theme file to the child theme and then make the changes in that file.
    Downside: It will not let my child-theme take advantage of parent-theme updates.

    2. Make changes in CSS. By changing CSS it is possible to turn off features. Example:

    .foo {
    display: none;
    }

    Downside: The code will still be run, which means that performance will not be enhanced.

    3. Make changes in child-theme functions.php.
    Take away functions in parent theme by creating an empty functions.php file in the chile-theme and the use functions like remove_parent_theme_features() to turn off features.

    So, from what I have understood these are the three ways to do it. It seems to me that the third way would be the best, since it will enhance performance (by getting rid of excess code) and not mess upp future theme-updates.
    So, should option three be considered best practice, or have i misunderstood this all together? Or are there other ways to solve this problem?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Yes, you have misunderstood. CSS changes are made in the child theme style.css file – only changes go in that file – which are loaded AFTER the parent theme CSS – so they will (if they are coded correctly) override the parent theme CSS.

    Child theme functions.php file can be used for modifying parent theme functions or adding new ones. BUT do not copy the parent theme functions in there without knowing what you are doing – it can crash the site.

    For template files, copy the parent theme one into the child theme and make the change in that copy – the child theme will only load the child theme template file. NEW template files can also be added to the child theme.

    The above “3 ways” are not alternatives to each other – they each do different things.

    Thread Starter pezbonoba

    (@pezbonoba)

    Thank you Mr. Moderator!

    So, say for example that I don’t want this code, that is found in the footer.php in the parent theme: `
    <div class=”site-info”>
    © <?php echo date(‘Y’); ?> <?php bloginfo( ‘name’ ); ?></div>`

    How should I go about removing that?
    I could just put this code in the child-theme style.css file:

    .site-info {
    display: none;
    }

    Which would make it not display on the website.

    Or I could upload parent-theme file footer.php to my child-theme and just take the code away. That would also solve the problem.

    Or, I could use some function in my empty functions.php file in my child theme to disable the code.

    Which is the prefered way, and why?

    First, I’m female :)!

    Yes, in that case, you can do that any of those ways – probably doesn’t make much difference which one you pick.

    Thread Starter pezbonoba

    (@pezbonoba)

    First, sorry! The Mr. part was stupid of me!

    Second: Alright, thanks!

    No worries :)!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Change code in child theme – Three different ways?’ is closed to new replies.