Site logo

Archived topic

Hooks Element or Code Snippets?

5 replies · Started by Rui on December 30, 2018

Viewing posts 1–6 of 6

As said in docs.generatepress.com/article/adding-php/ we can use Code Snippets plugin to add a function to our websites or to hook something into the theme.

But we also could use the Hook Element (native of GP). So... Why use Code Snippets?

Is there any situation where it is essential and the Hook Elements can not do work?

Or we can basically run any PHP code 'wherever' we want on theme (using Hooks) without installing the plugin?

Hi there,

Simple answer is no. Hooks are only used for content you want to run in that specific hook.

Things like filters and other custom functions need to be added using the adding PHP methods.

Hope this helps!

Well, let me see if I got it.

So, if I need to execute PHP code on certain pages the Hook Element will be the soluction.

But if have specific functions and filters on my theme (and do not create a child theme) then I should install the Code Snippets plugin.

Is it something like that?

Not quite.

So, if I need to execute PHP code on certain pages the Hook Element will be the soluction.

If you need the PHP code to execute inside specific hook then yes.

A plugin like Code Snippet should have minimal impact on the speed of your site so I really wouldn't worry about it.

Ok, Leo. Thank you.
I'm still getting familiar with these details!

Happy New Year!

Happy new year to you too :)

This archived topic is closed to new replies.