D
D
Denis99992018-06-10 20:31:03
WordPress
Denis9999, 2018-06-10 20:31:03

Overriding a function in a Wordpress child theme?

In the parent theme, the function is simply declared, without the use of function_exists:

if( ! function_exists('theme_function') ){
  function theme_function() {
    // Код.
  }
}

It turns out that there is no way to redefine the function in the child theme, but there is no point in adding if !function_exists to the parent theme, since this change will be erased when the theme is updated anyway.
Is there anything else that can be done in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Yanchevsky, 2018-06-10
@Denis9999

1. If the function uses hooks or is attached to hooks, unbind and attach your function.
2. If displayed in a template, redefine the template.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question