Community Forums › Forums › Archived Forums › General Discussion › Using functions file instead of Simple Hooks
- This topic has 4 replies, 2 voices, and was last updated 10 years ago by
Brad Dalton.
-
AuthorPosts
-
May 26, 2013 at 6:52 pm #42739
emasai
ParticipantI have been using Simple Hooks for a while but would really like to know how to write these into the functions file. I have read Nick the Greeks Genesis Explained series, which still remains all Greek to me as it is obviously over my level of programming comprehension. I just read, comprehended and implemented a great tutorial on creating and placing a widget via functions - http://wpdaily.co/genesis-hooks/
This is the type of tutorial or explanation I'm looking for. Does anyone know of one or can explain how to do this in a simple fashion?
Thanks
Need Website Customization or a Responsive CSS fix? Contact Me
Lynne emasai.comMay 26, 2013 at 11:39 pm #42760Brad Dalton
ParticipantThere are 2 differences between pasting PHP code into the Simple Hooks field and using the same code in a custom function in your child themes functions.php file.
1. Firstly, all PHP in simple hooks needs to be wrapped in opening and closing PHP tags
2. Secondly, PHP in simple hooks doesn't include any of the genesis_hooks in the code because the field already outputs your PHP using that hook.
Example: If you want to display a slider on the home page using Simple Hooks, you would paste this code into one of the genesis_hook locations. Most likely, the genesis_header hook.
You could do exactly the same thing using a custom function in your child themes functions.php file and this is the code you would use.
You can clearly see both code snippets include the tag for the slider however the difference between the 2 code snippets is this:
The second code snippet includes the genesis_header hook in an add_action which hooks the slider into the header hook position and isn't wrapped in PHP tags as the tags are already included in the functions.php file.
Its also includes a function using a unique name which describes what the code does. This must be different to the names of all other functions in Genesis and your child theme.
Learn more:
http://designsbynickthegeek.com/tutorials/conditional-page-content
http://devzone.zend.com/4/php-101-part-1-down-the-rabbit-hole/
May 27, 2013 at 10:12 am #42808emasai
ParticipantThank you so much for your clear and informative reply. I am now starting to "get it" - yeah! I have also bookmarked your site and code snippets.
Thanks again.
Need Website Customization or a Responsive CSS fix? Contact Me
Lynne emasai.comMay 27, 2013 at 2:40 pm #42828emasai
ParticipantOne question, what is the reason for adding
"&& function_exists('easing_slider')"
Thanks
Need Website Customization or a Responsive CSS fix? Contact Me
Lynne emasai.comMay 27, 2013 at 9:35 pm #42861Brad Dalton
ParticipantIf the Easing slider plugin is installed, then execute the code and display it in the hook location.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.