WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How best to preserve mods to theme files? (5 posts)

  1. Nate
    Member
    Posted 7 years ago #

    Greetings, all,

    Some searching didn't uncover an answer to this question, so here I am. I'd be grateful for a smidge of your time.

    In short: I'm making some modifications to the template files for the theme I'm using (the theme in this case being Sandbox, but that doesn't matter), and I'm trying to figure out how best to preserve those changes so that when I upgrade to a new version of the theme, I don't have to re-apply everything manually.

    It appears that my-hacks.php is *not* relevant here, as that file is only used for preserving changes to WordPress' core files when upgrading to a new version of WordPress itself. Is that right?

    A few random examples of the theme mods I'm referring to:

    1) Capitalization stuff on buttons.
    2) Making certain boilerplate text more personal (eg, in the 404 file).
    3) The addition of scripts needed to talk to external services (eg, Google Analytics). I'm obviously not counting stuff that's inserted by plugins, since the plugin typically continues to work after a theme upgrade.

    Again, suggestions would be much appreciated. Thanks! :)

    Nate

  2. Dgold
    Member
    Posted 7 years ago #

    I don't know the answer, but I have the same problem.

    I have hesitated to upgrade my default-theme because of my custom modifications I've made since I first met WordPress. Therefore I am still using my custom version of Kubrick from WP1.5, even though there is a newer Kubrick default in WP2.

    I just don't have a way to know all the little tweaks I made, they're everywhere! I wish I had known more about how to do Commmenting in my PHP files, I should have put some /* Dgold Modified This!!! */

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    There is no really good way to do this with themes. Sorry. When you change themes, your hacks/mods have to be re-implemented.

    However:

    3) The addition of scripts needed to talk to external services (eg, Google Analytics). I'm obviously not counting stuff that's inserted by plugins, since the plugin typically continues to work after a theme upgrade.

    In these cases, you'd be best off moving these additions to a custom plugin or somewhere else outside of the theme itself. For example, Google Analytics requires the addition of a small bit of code into the header. This could be accomplished like so, in PHP:
    <?php
    function insert_my_google_analytics() {
    ?>
    *insert Google code here*
    <?php
    } // end function
    add_action('wp_head','insert_my_google_analytics');
    ?>

    This would be theme independant, since virtually every theme calls the wp_head() function in the header. These are called "action hooks", and you can find more about them in the codex.

  4. Nate
    Member
    Posted 7 years ago #

    Otto--Thanks for your reply. Not the best news, no, but at least I now know where to focus my efforts! :)

    I'll consider how best to manage these mods as my site grows and the mods mature, but for the time being I should start with a very basic followup: In the example you give, would insert_my_google_analytics() be defined in functions.php? I'm (clearly) not a WordPress maven or a programmer in any sense, but I'm certainly willing to learn.

    Thanks again.

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    functions.php would be one place, but the problem there is that functions.php is part of the theme. It's only theme independant if the theme doesn't have it's own functions.php.

    my-hacks would be a better place, or write your own plugin to fill in these bits. I have a custom plugin specific to my blog where I put hacks like these.

Topic Closed

This topic has been closed to new replies.

About this Topic