Community Forums › Forums › Archived Forums › General Discussion › Customize genesis_get_image_id() function on child theme
- This topic has 2 replies, 2 voices, and was last updated 10 years, 7 months ago by darkpollo.
-
AuthorPosts
-
March 16, 2014 at 6:46 pm #95231darkpolloMember
Hi,
I would like to modify the function genesis_get_image_id(): from the image.php file on genesis theme using a child theme but when i tried to add the function into the child theme it returns an error sayiing that it has been already loaded or something like that.
Do you know how can I modify that function without modifying the original code?
Thanks
March 17, 2014 at 1:35 pm #95366Brad DaltonParticipantYou need to find the filter and use that in a custom function.
Really depends on what you want to do specifically.
IMAGE FILTERS
genesis_get_image_default_args
Default value: $defaults
applied to the default arguments added to genesis_get_image function.genesis_pre_get_image
Default value: false, $args, $post
Allows child theme to short-circuit the genesis_get_image functiongenesis_get_image
Default value: $output, $args, $id, $html, $url, $src
March 17, 2014 at 1:57 pm #95373darkpolloMemberI want to replace the actual genesis_get_image function code and use a new function of my own.
Normally, when you replace a function using a child theme, the one on the main theme does not load, but here on genesis it loads first the main theme. I think this is a problem that needs to be fixed on the main code.
From the wordpress guide:
https://codex.wordpress.org/Child_Themes
Using functions.php
Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)In that way, the functions.php of a child theme provides a smart, trouble-free method of modifying the functionality of a parent theme. Say that you want to add a PHP function to your theme. The fastest way would be to open its functions.php file and put the function there. But that’s not smart: The next time your theme is updated, your function will disappear. But there is an alternative way which is the smart way: you can create a child theme, add a functions.php file in it, and add your function to that file. The function will do the exact same job from there too, with the advantage that it will not be affected by future updates of the parent theme. Do not copy the full content of functions.php of the parent theme into functions.php in the child theme.
TIP FOR THEME DEVELOPERS. The fact that a child theme’s functions.php is loaded first means that you can make the user functions of your theme pluggable —that is, replaceable by a child theme— by declaring them conditionally. E.g.:
if ( ! function_exists( 'theme_special_nav' ) ) { function theme_special_nav() { // Do something. } }
In that way, a child theme can replace a PHP function of the parent by simply declaring it beforehand.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.