Using Actions/Hooks in Child Themes

So, if you’ve been using Child Themes for awhile, you might be very used to the normal way of modifying our themes. You take a file (like 404.php, archive.php, or another file in the root directory) and copy it into your child theme. Then you make a few modifications, and bam! It works.

This is awesome. But the problem is that it only works for the code in the root directory. These files in the root directory are called ‘templates’, and WordPress automatically makes the files child theme friendly.

The issue is that there is a whole other set of files that you can’t do this with. They are called ‘core files’. In Vantage (and other themes), this includes every file outside of the root directory (/includes/, /framework/, etc). These files are used for lots of different complicated jobs that go into making our themes so powerful. And just like it wouldn’t be a good idea to just start going in and replacing parts of WordPress, you don’t want to start replacing random parts of themes.

Hooks & Filters

But just because you can’t just go in and replace stuff, doesn’t mean you shouldn’t be able to customize how the theme works. That’s why WordPress has Hooks and Filters. They let you inject your code into certain parts of our themes without breaking things (most of the time).

The best way to learn about Hooks & Filters is to read about it on the WordPress Codex. Ignore the part where they call it the Plugin API, it works just fine for themes as well.

Read that? Cool. Let’s keep going.

Hooking into Vantage (or other themes)

Given you just read about hooks, you know that when you add a function to a certain event, WordPress will call that function when the event happens. For instance, I can hook a function to ‘save_post’, and it will be called every time the post is saved.

The cool part about this is it is just as easy to hook something as it is to unhook something. Let’s say the following code was in a core file in Vantage:

add_action( 'save_post', 'va_email_me' );
function va_email_me( $post_id, $post ){
    wp_mail( '', $post->post_title, 'This post was posted' );

Let’s say that you want the email to go to instead of Well, you can’t just go in and change the line of code because it would get overwritten the next time you update. You might be thinking, I wish AppThemes had put in a filter so I could change the email address.

Well, instead of posting a request and waiting for our response, you can simply use a child theme or function to unhook our function, and replace it with yours.

remove_action( 'save_post', 'va_email_me' );
add_action( 'save_post', 'my_email_me' );
function my_email_me( $post_id, $post ){
    wp_mail( '', $post->post_title, 'This post was posted. YAY' );

As you can see, in our child theme’s functions.php, we simply made a call to remove the action that hooks ‘save_post’ and Vantage’s ‘va_email_me’ together, and added our own version of it.

This method works with almost all of our code. In Vantage, there are over 190 calls to ‘add_action’.

However, you should be careful with the things you unhook. We don’t put in any code in Vantage that we don’t deem necessary to making our product as awesome as possible. So, if you unhook some really core things (registering custom post types, taxonomies, etc), be prepared for some things to not work right.

Like this tutorial? Subscribe and get the latest tutorials delivered straight to your inbox or feed reader.

Your rating: none
Rating: 4.7 - 11 votes

Written by: on September 18, 2012. Last modified: September 22, 2012

Popular Marketplace Items

  • screenshot


    A conversion focused responsive Clipper child theme with premium features.
  • classipress-fortumosms-gateway

    Fortumo SMS payment gateway

    Fortumo sms payment gateway for ClassiPress
  • autoauto-thumbnail

    AutoResponder AutoRegistration

    Automatically integrates WordPress registration with major autoresponders.
  • featured

    QR Codes Widget

    Add a widget with QR codes to your AppThemes site.
  • 2Checkout Payment Gateway Plugin


    Accept up to eight payment methods, fifteen languages, & twenty six currencies.
  • critic-icon-2


    A professional review and rating system for WordPress.
  • at_autosuggest_taskerr_thumb

    AutoSuggest – Taskerr

    Automatically suggests services as the user types.
  • woo_goodstore_thumb


    A clean, modern and fully responsive WooCommerce Fashion Theme.
  • adposter-blocker-thumbnail

    AdPoster Blocker

    A simple but powerful plugin that blocks spammy new user regs and/or ads/jobs/posts.
  • StarStruck WordPress Plugin Thumbnail


    A fast, lightweight, and elegant star rating system for comments, pages, & posts.
  • GeoReg thumbnail


    Captures detailed geographic info with new user registrations.
  • AppThemes Coupon Plugin

    AppThemes Coupons

    An easy way to start offering coupons and promotions to your customers.
  • Custom Greeting

    Custom Greeting

    Easily replace the default WordPress greeting.
  • balanced-payments-plugin-sm

    Balanced Payments

    Accept credit cards and setup escrow payments.
  • wp-smart-export-final

    WP Smart Export

    A highly customizable WordPress data exporter plugin.
  • Authorize.Net Thumbnail


    Easily start accepting online payments via credit card and e-check.
  • thumnail

    Category Icons

    Add icons to your ClassiPress categories
  • woo_marine_thumb


    A clean, modern and fully responsive marine-based goods WooCommerce Theme.
  • classpress tabber


    Show specific custom fields as tabs on an ad detail page.
  • daddy-likes-190x130

    Daddy Like

    A fast, lightweight, and elegant "like" system for comments, pages, posts, & activities.
  • stripe-plugin


    Process credit cards safely and securely on your AppThemes website.
  • pcp-featured

    Price Comparer

    Jump start your Price Comparision site with products from Amazon, Commission Junction, and LinkShare.