Site logo

[Resolved] Adding custom PHP through a Hook

Home Forums Support [Resolved] Adding custom PHP through a Hook

Home Forums Support Adding custom PHP through a Hook

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1840150
    Sal C

    Hi,

    I have noticed that under Hook > Settings there are 2 checkboxes – “Execute PHP” and “Execute shortcodes”.

    I want to add a custom PHP code to my pages, which enables me to add a custom shortcode. Therefore, these 2 checkboxes seemed to perfectly fit my use case. However, I have been unable to successfully load my PHP through a Hook – even with these 2 checkboxes enabled. Instead, I was able to make it work through a child theme.

    Could you clarify what the purpose of these 2 checkboxes is? Also, is there a way to actually execute PHP with a Hook element. It would be very useful to me because I would like the custom PHP to loaded only on select pages.

    I look forward to your reply.

    Best regards,

    Sal

    #1840151
    Leo
    Staff
    Customer Support

    Hi there,

    What is the code you are adding?

    Usually custom PHP code needs to be added using one of these methods:
    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #1840177
    Sal C

    Hi,

    I can’t share it right now. It calls on an external API in order to update a shortcode.

    I did use the child theme methos outlined in that article, and it worked as expected. Would it be possible to only load the PHP code I added to the child theme only on a specific page?

    Thanks,

    Sal

    #1840179
    Leo
    Staff
    Customer Support

    You will need to modify the code and use the conditional tags from WordPress:
    https://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

    #1840199
    Sal C

    Thanks, I appreciate it.

    Best regards,

    Sal

    #1841348
    Leo
    Staff
    Customer Support

    No problem 🙂

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