Archived topic
Adding custom PHP through a Hook
5 replies · Started by Sal C on June 30, 2021
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
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/
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
You will need to modify the code and use the conditional tags from WordPress:
https://codex.wordpress.org/Conditional_Tags#A_PAGE_Page
Thanks, I appreciate it.
Best regards,
Sal
No problem :)