Override a function with child themes functions.php Override a function with child themes functions.php wordpress wordpress

Override a function with child themes functions.php


the parent theme needs to check if(function_exists('ajax_search_box')) and if it doesn't exist then it will declare it.

If the parent theme checks to see if the function exists, then you can declare it first and have it do what you want.

If the parent theme does not check, get in touch with the theme author to see if they will throw that change in for the next update....and code it yourself too. That way when the theme updates then you will still be good to go.


Break free of functions.php, write your own plugin.

<?php/**  * Plugin Name: Manipulate the Parent  * Requires: PHP5.3+ */add_action( 'after_setup_theme', function(){    remove_filter( 'pre_get_posts','SearchFilter' );        // now add your own filter    add_filter( 'pre_get_posts', 'your_callback_for_your_filter' ); });function your_callback_for_your_filter(){     // do stuff}