[Resolved] Hooks Element or Code Snippets?

Home Forums Support [Resolved] Hooks Element or Code Snippets?

Home Forums Support Hooks Element or Code Snippets?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #769296
    Rui

    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?

    #769305
    Leo
    Staff
    Customer Support

    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!

    #769472
    Rui

    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?

    #769477
    Leo
    Staff
    Customer Support

    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.

    #769553
    Rui

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

    Happy New Year!

    #770018
    Leo
    Staff
    Customer Support

    Happy new year to you too 🙂

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