Premium WordPress Themes, Templates & Plugins › Support › WordPress Theme Support › LastPoint › Child Theme's Functions
- This topic has 8 replies, 2 voices, and was last updated 8 years, 11 months ago by ThemeofWP.
- AuthorPosts
-
- April 23, 2015 at 4:53 am #2981jpwelchMember
I’m using a Child Theme and would like to override some functions in the functions.php file from the Parent theme. Is it possible for you declare the functions conditionally in the Parent theme so it can be overridden in the child theme. For example.
if ( ! function_exists( 'themeofwp_top_ajax_login' ) ) { function themeofwp_top_ajax_login() { // code } }
- May 5, 2015 at 9:01 pm #3012jpwelchMember
checking in on this request. is it possible or do you suggest a better way to update these functions in the function.php file?
- May 6, 2015 at 7:14 pm #3015ThemeofWPKeymaster
please copy functions.php in to teh child theme folder then mofify it a your needs. or you can copy the whole function and modify it as your needs.
function themeofwp_top_ajax_login(){
- May 6, 2015 at 7:24 pm #3016jpwelchMember
I believe this reply was for the post “Child Theme’s Function” post. https://themeofwp.com/old-support/topic/child-themes-functions/
note: when you try to override a function that doesn’t have a if exists function logic check it crashes the site because it sees multiple functions with the same name. you get an error indicating that a function exists already.
thanks
jean-pierre - May 7, 2015 at 9:32 pm #3020ThemeofWPKeymaster
Please copy a blank functions.php into the child theme. Do this in parent theme functions:
if ( ! function_exists( 'themeofwp_top_ajax_login' ) ) { function theme_special_nav() { // Do something. } }
and use this in child theme functions.php
function themeofwp_top_ajax_login() {
// Do something.
} - May 8, 2015 at 4:24 am #3024jpwelchMember
This is what I’ve been doing. I am asking for the parent theme to always be set that way so I don’t have to touch the parent theme. I should only have to touch the child theme.
“If you modify a theme directly and it is updated, then your modifications may be lost. By using a child theme you will ensure that your modifications are preserved.”, https://codex.wordpress.org/Child_Themes
- May 11, 2015 at 8:35 pm #3028ThemeofWPKeymaster
Hi, Please update the theme and copy this function without if function exist like below into the child theme functions.php:
function themeofwp_top_ajax_login(){
}
then you can overwrite with the functions.
- May 14, 2015 at 6:28 pm #3043ThemeofWPKeymaster
I’ll mark it resoved now. You can change anything with your child theme now.
-
- AuthorPosts
- You must be logged in to reply to this topic.