WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Sep 09 2011

How to Replace Functions Regardless of the Genesis Hook (via Gary Jones)

Recently, Gary Jones (@GaryJ) posted a bit of code for Jared Atchison (@jaredatch) on Twitter for a plugin that he is working on that will remove functions regardless of where they get hooked. It is a great piece of code. If you find this helpful, please support Gary or tell him how much you appreciate him.

[php]<?php
// Run at get_header to catch all customisations in functions.php

add_action( 'get_header', 'jared_remove_stuff_whichever_hook_they_are_on' );
/**
* Replace some genesis_* functions hooked into somewhere for some jared_* functions
* of the same suffix, at the same hook and priority
*
* @author Gary Jones
*
* @global array $wp_filter
*/
function jared_remove_stuff_whichever_hook_they_are_on() {

global $wp_filter;

// List of genesis_* functions to be replaced with jared_* functions.
// We save some bytes and add the ubiquitous 'genesis_' later on.
$functions = array(
'do_doctype',
'do_nav',
'do_subnav',
'header_markup_open',
'header_markup_close',
'post_info',
'post_meta',
'do_loop',
'footer_markup_open',
'footer_markup_close'
);

// Loop through all hooks (yes, stored under the $wp_filter global)
foreach ( $wp_filter as $hook => $priority) {

// Loop through our array of functions for each hook
foreach( $functions as $function) {

// has_action returns int for the priority
if ( $priority = has_action( $hook, 'genesis_' . $function ) ) {

// If there's a function hooked in, remove the genesis_* function
// from whichever hook we're looping through at the time.
remove_action( $hook, 'genesis_' . $function, $priority );

// Add a replacement function in at the same time.
add_action( $hook, 'jared_' . $function, $priority );
}
}
}

}[/php]

Written by Travis Smith · Categorized: Genesis

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in