Viewing 7 reply threads
  • Author
    Posts
    • #2981
      jpwelch
      Member

      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
          }
      }
      
    • #3012
      jpwelch
      Member

      checking in on this request. is it possible or do you suggest a better way to update these functions in the function.php file?

    • #3015
      ThemeofWP
      Keymaster

      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(){

    • #3016
      jpwelch
      Member

      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

    • #3020
      ThemeofWP
      Keymaster

      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.
      }

    • #3024
      jpwelch
      Member

      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

    • #3028
      ThemeofWP
      Keymaster

      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.

      • #3041
        jpwelch
        Member

        Thanks for this update.

    • #3043
      ThemeofWP
      Keymaster

      I’ll mark it resoved now. You can change anything with your child theme now.

Viewing 7 reply threads
  • You must be logged in to reply to this topic.