Archived topic
With all else being equal, what's the best way to add PHP snippets?
5 replies · Started by Jay on August 11, 2018
I saw someone ask a similar question in a recent thread, but I wanted to pose it a little differently.
In this article (https://docs.generatepress.com/article/adding-php/), it's recommended to add PHP to GeneratePress using one of three methods:
1. Code Snippets plugin.
2. Create your own custom plugin.
3. Child theme.
I realize there are pros and cons to each and one method may be better than another depending on the specific context.
But ignoring all of that for a minute, which method is best regardless of context? Meaning, if a person was equally comfortable using all 3 methods and strictly wanted to choose the one that would be most ideal in terms of speed/performance... which method wins?
Thanks.
Performance-wise, creating your own plugin and using a child theme should be identical. Code Snippets is likely not as good for performance, as WordPress needs to read and execute the code.
If you're using a child theme, you might as well use the functions.php.
If you're not using a child theme, then a plugin is likely the way to go.
Thanks Tom, exactly the answer I was looking for. The level of support here is fantastic.
If I can throw a follow-up at you: the same exact question, but with CSS?
Simple CSS vs Additional CSS in the customizer vs child theme’s style.css in terms of performance?
Simple CSS adds the CSS to the database, which WordPress needs to query and output (in the <head>). It adds a query, but it's not very expensive at all.
Additional CSS is added as a post type I believe, so I assume the query is a little more expensive than Simple CSS.
The child theme just enqueues a CSS file, which is likely the least expensive query when it comes to CSS. Browsers will also cache the static file, which is a bonus for performance.
Exactly what I needed to know, thanks!
You're welcome :)