0

I was watching this video on how to customize WP theme: https://www.youtube.com/watch?v=O8Nnn06Um0I

It seems like I have to copy the whole php from the parent theme to the child theme and modify it in the child theme.

My question: Is there a better way of doing this so that when the parent theme's upgrade, I don't have to diff it with my changes?

A) If that question is too much of an opinion-based question, I would like to ask if there's a way to change the output HTML from a plugin dynamically?

B) Or, more generically, is there a way to customize the theme by writing a plugin instead of creating a child theme? Can you go over when that will be beneficial and how to achieve?

2/9/17 UPDATE: Changed title from "How can I customize a theme via a plugin/change HTML output/change only a portion of the php file?" to "How can I customize a theme via a plugin?"

Thank you to everyone (@David Lee, @Samyer, @Rick Hellewell) who tried to answer this question so far... I do understand how to create a child theme and the answer that I got so far is that it's best to customize the theme by using a child theme, not via a plugin.

I'm updating my question because if I use the child theme approach, my question would then be the same one as the one listed here: Theme/Plugin customization (specifically for classiads): Where do I change the code?

Now, I know it's not recommended, but just so that I understand my options, my question is: What is the "best" way to update a theme via a plugin? I'm looking to understand how this works also. i.e.: Since it's not in a child theme, will the css all be stored in the DB somewhere and when the HTML output is rendered, one intercept it and modify the HTML or something?

Thank you.

  • You don't have to copy all of the parent theme files, just reference it as parent theme, you can just have the basic files for a theme, using a plugin for that is a no-no because it will add complexity not only from the theme perspective but also the plugin and WordPress perspective, so if there is any update in any of these, you will likely have to update your code, versus the simple child-theme with 2 to 3 files. Basic Theme Files – David Lee Feb 7 '17 at 18:12
0

Check out this link: https://developer.wordpress.org/themes/advanced-topics/child-themes/

Any php file (except the functions.php) in your parent theme will be overridden if there is a file with the same name in your child theme. So the only files you need in your child theme are those that you want to change. The functions.php file is a bit different. The child's functions.php file will be loaded BEFORE the parent's functions.php file, but both are loaded.

  • Child themes are the way to go, as @Samyer mentioned. If you have a function in your Child Theme's functions.php with the same name as a function in the parent theme, the Child Theme's function will override the one in the parent theme..... ....if the theme is declaring functions the proper way by checking for the function already exists. Otherwise, you will get errors about the function already being defined. Most themes do write their functions the proper way, but that's where to look if you get 'function already defined' - type errors. – Rick Hellewell Feb 9 '17 at 2:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.