Site logo

[Resolved] With all else being equal, what's the best way to add PHP snippets?

Home Forums Support [Resolved] With all else being equal, what's the best way to add PHP snippets?

Home Forums Support With all else being equal, what's the best way to add PHP snippets?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #645874
    Jay

    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.

    #646049
    Tom
    Lead Developer
    Lead Developer

    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.

    #646054
    Jay

    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?

    #646060
    Tom
    Lead Developer
    Lead Developer

    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.

    #646548
    Jay

    Exactly what I needed to know, thanks!

    #646628
    Tom
    Lead Developer
    Lead Developer

    You’re welcome šŸ™‚

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.