I have a PHP template in my child theme that calls a function ale_filter(), via

        <div class="articles">
            <?php ale_filter($_POST);?>
        </div>

The function is defined in a parent theme file: /aletheme/functions.filter.php. I would like to copy this file to my child theme, make edits to the function, and ensure the PHP template in-question calls this function, and not the parent theme function. How do I do so?

I have already copied the parent theme file to my child theme, using the same file name and relative path (/aletheme/functions/filter.php).


A previous Stack Exchange question linked to a page with three methods. Those three methods were:

  • Taking advantage of pluggable functions – This method applies only if the parent theme function is pluggable. Mine is not.
  • Increase priority for child theme function – I’m not entirely sure how to do so in my case. The example given was for a parent theme function attached to a WordPress hook, and mine is not. The PHP man page on proc_nice wasn’t that clear either. I guess I could follow-up on that a bit though. Maybe someone here has ideas.
  • Making use of hooks, actions and filters – This method applies only if the parent theme function is attached to a WordPress hook. I don’t believe that applies in my case.

I found several other Stack Exchange questions, but the answers in all described methods that I do not think apply in my case:

  • How to override parent theme function through the child theme
  • Function in Child Theme not overriding Parent Theme function
  • How to override function in child theme
  • How to override the Parent theme Function into child themes functions.php
  • How to override parent functions in child themes?

Thanks.

1 Answer
1

Since the function is used in your child theme’s template there’s nothing stopping you from using a function with a different name. So you don’t actually need to plug the function, you just need to create a function that does what you want and use that instead.

So copy ale_filter() to your child theme, rename it something like ale_child_filter(), change it however you like, and then just change your template to use that function.

You only need to plug a function if the function is used somewhere that you can’t overwrite with your child theme. Plugging it would allow you redefine a function when you don’t have access to change where the function is used. Since you do have the ability to change which function is used, plugging the function is unnecessary.

Leave a Reply

Your email address will not be published. Required fields are marked *