How to: Overwrite WordPress core functions
Posted by Jean-Baptiste Jung on Nov 11, 2008 in WordPress • 21 commentsI have read many “tutorials” which told users to modify WordPress core files. This is a really, really, bad idea. Why? Simply because you’ll have to modify that file again when you’ll upgrade your blog. Here’s how to overwrite WordPress core function without modifying any core file.
Why overwriting instead of replacing?
At first, modifying a core file seems a lot easier than overwriting it. But what will you do when you'll have to upgrade your blog? New WordPress versions are released something like every two months, so it might be a long and boring work to reimplement each core file you previously modified.
Happilly, there's a solution to that problem. It is WordPress specific functions calls filters. For exemple, when you install a WordPress plugin which modify some WordPress core functionnality, you can be sure that the plugin uses a filter.
Using filters
As I said, a filter can be used within a plugin. But that's not necessary: You can also use it on the functions.php file from your theme. If your theme doesn't have a functions.php file, you should create it.
The most common WordPress filter function is called add_filter():
add_filter('hook_name', 'your_filter', [priority], [accepted_args]);
Let's study the required and optionnal parameters in detail:
- hook_name: (required) the name of the hook provided by WordPress. It defines when your filter will apply.
- your_filter: (required) The custom function to call instead of hook_name.
- priority: (optionnal) used to specify the order in which the functions associated with a particular filter are executed.
- accepted_args: (optionnal) The number of accepted arguments.
Exemple use of the add_filter() function
Let's see how to use the add_filter() function with a practical exemple. The following code overwrites the bloginfo() function.
add_filter('bloginfo', 'mybloginfo', 1, 2);
add_filter('bloginfo_url', 'mybloginfo', 1, 2);
function mybloginfo($result='', $show='') {
switch ($show) {
case 'wpurl':
$result = SITE_URL;
break;
case 'template_directory':
$result = TEMPL_DIR;
break;
default:
}
return $result;
}
Removing filters
While it is possible to add new filters to overwrite WordPress core functions, it is also possible to remove existing filters. For exemple, many people who publish code on their blog are tired about the curly code, because it breaks the code. A WordPress function called wptexturize() replaces normal quotes with curly quotes. As this is a filter, it is possible to simply remove it and get rid of theses curly quotes:
<?php remove_filter('the_content', 'wptexturize'); ?>
Nothing hard, isn't it? You now know how to overwrite WordPress core functionnality without editing core files, as well as removing unwanted filters.

















Well, it is not hard when you, master of Wp, are explaining it :). Thanks for sharing. Indeed very useful as i didn’t know it was possible to overwrite core wp functions.
Thanks Catrin, I appreciate your kind words
Excellent post. I’m surprised not to see more info like this - everyone seems to focus on the theming and theme related functions rather than the back-end/core issues. Thank you!
Thanks for sharing the information
Nice article
Well, I generally tend to get into the code details,but Wordpress is new to me. These little tutorials help immensely. I am currently redesigning and rebuilding my entire website in Wordpress so these posts are extremely useful to me.
I use your website as my browser home page so I don’t miss anything.
I´ve actually just started blogging and I need to read up on word press and templates etc. I´ve come across a few blogs which give a lot of information, which is always good for beginners like me. I´d ike to think I´ll get the hang of it all soon - fingers crossed!
Frank
Hi, this helpd me out alot, but i wanted to ask if you had a list of all the hook name’s, since theres alot of them.
@Omar: You can find some hooks here.
Well, that’s a nice article if i understood it! LOL!! I am more than sure that the piece of code you provided is going to be quite useful to…people who know their way through Wordpress. As far as I am concerned i had to read your article twice just to find out that i didnt know what it was talking about. I just know how to upgrade my blog and my plugins plus some other nice tricks to protect it and how to work with http://ftp…and that’s it! ta-da! When something goes wrong i have, as a last resource, pay to get the job done..sad but true!
The term overwrite in this context is not strictly correct since using hooks only “hooks” your code into the wordpress function that is already being executed. It allows you to additionally manipulate the data after wordpress is done with it. If you really want to overwrite a wordpress function, then I’d suggest copying the code for the desired function into your functions.php file, giving it a different name, changing the code to suit and then calling that function everywhere in your template.
@Robert: Thanks for the correction!
very well said post
I still overwrite core files because adding filters can be more difficult depending on the scenario
Well, right now I am trying to write a couple of plusings to learn how to use filters properly. May be after that…
Hello jrj..
How about function / filter to hide or replace some word at admin area. For sample, at header i want to replace “Howdy” with “Logged User :” or at footer, I want to replace “Thank you for creating with Wordpress” with “Powered by Wordpress”
Thx before and after..
Thank you, this is a big help to a problem I’ve been having.
I am currently redesigning and rebuilding my entire website in Wordpress so these posts are extremely useful to me.
I learn new lesson here, some themes have function php file, some not … thank you