Site logo

Archived topic

Why can you enable/disable php in the "Hook" element?

5 replies · Started by Mike on November 2, 2018

Viewing posts 1–6 of 6

Hi there,
I have two questions:
#1: Why can you enable/disable php in the "Hook" element settings? Why isn't this activated by default?
What is the technical reason for that, or what would be a usecase of this?

#2: When I'm designing the frontpage of a website, I do the following:
I add the Hook 'inside_container', location: "Front Page" and inside this hook, I put my html markup (which is styled through the style.css).
Is this the right way of doing it, or is this kind of "hacky"?

Thanks in advance.
Mike

Hi there,

1. It's mostly for security reason. If you aren't adding PHP in hooks, it's best to not execute PHP.

2. That sounds like the right way to do it. Just make sure you are referring to child theme's style.css :)

Let me know if this helps :)

Ok, thank you very much.

Just a quick note on #1. It's not so much a security issue as it is a performance issue. When PHP is executed, more code has to execute in order to read and output the PHP. If PHP isn't needed, it's more performant to skip that extra code from executing.

Ok, but if you need php, then you can not disable it.
And if you dont need it there is no php to execute in the first place, hence no performance issues.
So what is the point in having the option of enabling/disabling it instead of it being enabled by default?
Isnt the hook inserted inside the page.php file?

I am just asking because I love working with your theme and would like to learn more about how it works :)

Enabling PHP execution executes extra code on the frontend of the site. All of the content is pushed through this extra code, regardless of whether it's PHP or not.

That's why it's more performant to not execute PHP if it's not necessary.

This archived topic is closed to new replies.