Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
add_action('wp_head','add_gpp_gallery');
function add_gpp_gallery() {
    if( ( is_single() || is_page() ) && ( !is_page_template('page-blog.php') ) ){
        remove_shortcode('gallery', 'gallery_shortcode');
        add_shortcode('gallery', 'gpp_gallery_shortcode');
    }
}

Hi All, I pulled the above function out of the plugin's core functions file, and I was hoping to change it to only replace the WP default gallery on my custom post type. So I changed the if statement above to:

if (is_single() && is_post_type('post_type'){

So I changed it and put it into my functions.php - but I'm getting an error that stating that I can't redeclare add_gpp_gallery

How would I override the plugin's functions without touching the plugin code?

thanks

EDIT

I tried:

remove_action( 'wp_head', 'add_gpp_gallery' );
add_action('wp_head','jason_add_gpp_gallery');
function jason_add_gpp_gallery() {
    if ( is_single() && is_post_type('listings') ){
        remove_shortcode('gallery', 'gallery_shortcode');
        add_shortcode('gallery', 'gpp_gallery_shortcode');
    }
}

and I get a fatal error -

Fatal error: Call to undefined function is_post_type() in /home/hostspro/public_html/movemaine.com/wp-content/themes/movemaine/functions.php on line 269

EDIT #2

I had cross wired my functions, and was forgetting to change out the is_post_type. The following code is working and thanks for the help

remove_action( 'wp_head', 'add_gpp_gallery' );
add_action('wp_head','jason_add_gpp_gallery');
function jason_add_gpp_gallery() {
    if ( is_single() && 'listings' == get_post_type() ) {
        remove_shortcode('gallery', 'gallery_shortcode');
        add_shortcode('gallery', 'gpp_gallery_shortcode');
    }
}
share|improve this question
1  
You can shorten your conditional from is_single() && 'listings' = get_post_type() to is_singular('listings'). The fatal error is because there is no is_post_type function. –  chrisguitarguy Aug 18 '11 at 13:07
add comment

1 Answer

up vote 1 down vote accepted

You can change the name of add_gpp_gallery function both in the callback and in the declaration to avoid the conflict between the original and your clone.

Something like this...

add_action('wp_head','jason_add_gpp_gallery');
function jason_add_gpp_gallery() {
    if ( is_single() && 'your_post_type' == get_post_type() ) ){
        remove_shortcode('gallery', 'gallery_shortcode');
        add_shortcode('gallery', 'gpp_gallery_shortcode');
    }
}

... should work for you.

Bonus: You can remove the original plugin action with remove_action() if needed.

share|improve this answer
    
Note that creating a unique function names anytime you write a function is considered an important practice as it prevents the exact conflicts you're experiencing. See Objective Best Practices for Plugin Development –  Michal Mau Aug 18 '11 at 12:05
2  
The "Bonus" is actually the answer. You need to call remove_action( 'wp_head', 'add_gpp_gallery' ), and then call your custom code (with properly namespaced function names). –  Chip Bennett Aug 18 '11 at 12:06
    
@Chip Thanks for clarifing this! No need to keep both of them. –  Michal Mau Aug 18 '11 at 12:10
    
Unfortunately - I get an error - see edit. –  Jason Aug 18 '11 at 12:17
2  
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.