Override plugin with functions.php

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

Read More

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');
    }
}

Related posts

Leave a Reply

1 comment

  1. 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.