WordPress.org

Ready to get started?Download WordPress

Forums

a few php files to affect all child themes (8 posts)

  1. andym193
    Member
    Posted 5 months ago #

    I am designing many child themes for my multisite.

    All my child themes will have exactly the same template files with same code and the same functions.php with the same code. They will also share some basic css.

    Because the child themes share many of the same things, if I ever get php errors or want to add things I have to go to each child theme to make changes. Also I am continuously going to add my own short-code emoticons so I will continuously be adding them which also means I have to keep going to all my child themes to add them.

    Is it possible to create a directory in my themes folder called main and then add a functions.php, add php templates that I will be editing, and a main css file in there where I can have them load first.

    So in every child theme functions.php it will 'only' have:
    <?php include '../main/functions.php'; ?>

    All my child theme template php files, for example, the header.php file will 'only' have:
    <?php include '../main/header.php'; ?>

    Then the css file in each child theme, I will add at the top of all my css code (for the main css changes):
    @import url("../main/style.css");

    So the main directory acts as the default, so I can add all my code to the files in the main directory and that way if I get errors, or I want to add things I only have to go to this main directory to make changes, then it will affect all my child themes.

    What are your thoughts on this system, I'm not good with php so will this have any affect on my website performance and is it secure, can it have any other problems?

  2. I think you don't know how child themes work.

    http://codex.wordpress.org/Child_Themes

    A child theme ONLY overrides what you replace, so if you don't make your own header.php, it will always use the one from the main theme.

  3. andym193
    Member
    Posted 5 months ago #

    Yes I know, thats why it would be even easier if I could edit the header.php, and functions.php in the parent theme so I can just make the changes to the parent theme. however, because of problems that I will have upgrading the parent theme, I need to find another way around this, that was the best I could come up with.

    If your familiar with magento ecommerce, Something similar to this is possible - it has the base directory (similar to wordpress parent theme)
    then you can create a default theme (this is where you can do all the major changes) then you can create another directory which is perfect for skinning the different stores, so Magento goes - 'base' then 'default' then 'theme' -
    so it create 3 levels of fallbacks, that is perfect for someone that has lots of different designed stores. If you create a lot of stores with your own designed themes this setup is a life saver.

    Ideally I need wordpress to be like magento and go: 'parent' then 'default' then 'child'. But it can't do that as it can only go 'parent' then 'child', which is bad news for my plans. So I'm trying to work out a another way around it like I mentioned with the php includes.

  4. andym193
    Member
    Posted 5 months ago #

    I hope someone can help me out with this conundrum, i'll explain another way:
    Imagine if I had 2000 child themes.
    in each child theme I had my edited function.php, header.php, and comments.php
    perfect.
    But now I have an error in the code of header.php
    I now have to go to all 2000 child themes to correct.
    Now I want to add an emoticon shortcode
    I now have to go to each 2000 child themes and upload the emoticon.gif in each child theme and add the emoticon shortcode to the function.php in each child theme.
    I now want to add some extra functions to function.php, so again I have to go to all 2000 child themes to add the same thing.
    I then get an error in the functions.php and so on.

    Can you see I need something between the parent theme and the child theme so I can just do these edits once. just like the magento default directory.

    This is why if I had somthing like <?php include '../main/(php file); ?> only in functions.php, header.php and comments.php in all of the 2000 child themes I can just go to the main directory (similar to magento default directory) where I can make the edits I mentioned above.

  5. *head scratch*

    1) If you're reproducing the exact same code in 2000 child themes, then you should be putting that code in the parent theme.

    2) If you're sharing a function amongst all your sites, I would put that in an mu-plugin instead.

    WP doesn't really do grandchildren themes. I mean you CAN do it but read this: http://wordpress.stackexchange.com/a/65853/7886

  6. andym193
    Member
    Posted 5 months ago #

    Thanks for the reference and your advice, its much appreciated. I am also using the genesis framework. Grandchildren themes would be ideal but I wouldn't want to use it if wordpress are not supporting it.

    The only thing that will be different between my child themes is css
    edits and images. (I'm not interested in a css plugin/ jetpack as I am a
    digital artist - I want to create my own skin themes and I like to give users a lot of variety). So any php changes (and main css changes to the framework) I need to just do once.

    Would putting code in the parent theme the best way to go do you think. So if I do an upgrade to the genesis framework, I should just replace the files each time.

    I would prefer not to use a plugin for sharing functions between all child themes, would it be okay to add this to the parent theme functions.php all at the bottom, then if I upgrade, I could just copy and paste my added functions to the new upgraded function.php at the bottom again.

    So just to clarify,
    would you suggest using the parent theme to make these main changes rather than something like for example, adding header.php to all child themes and just putting:
    <?php include '../default/header.php'; ?>
    Then create a default directory, and make my main changes to php files in there.

  7. andym193
    Member
    Posted 5 months ago #

    * I've just realized what an mu-plugin is, that might work for my functions.php, I'll look into that.

  8. Would putting code in the parent theme the best way to go do you think. So if I do an upgrade to the genesis framework, I should just replace the files each time.

    No, really the best thing would be to make ONE child theme with your custom changes in that. But you've yet to actually say if these 2000 child themes are different, and if so, how :)

    I mean, if it's something as basic as "Each site needs a different color/logo" that's one thing.

    I would prefer not to use a plugin for sharing functions between all child themes, would it be okay to add this to the parent theme functions.php all at the bottom, then if I upgrade, I could just copy and paste my added functions to the new upgraded function.php at the bottom again.

    Yeah, no, you want an mu-plugin for this :) Trust me. WAY easier.

    http://halfelf.org/2013/adding-per-site-multisite-options/ is one way around it. You could extend that and define a separate, secondary, CSS for each site to load as well.

    Or even an if then, and load siteID-style.css per site :)

Reply

You must log in to post.

About this Topic