skip to Main Content

I wondered if someone could help me with editing the wpshopify/wp-shopify.php in WordPress.
My goal is to make the Shopify plugin work on certain pages and not run on other pages.
So for example I would like the plugin to work on the [shop] page and not the [about us] page.
I have seen some "Plugin Organizers" but unfortunately I couldn’t make it work.

Does anyone have the experience or know-how to get this done?

2

Answers


  1. If you want to manage the styles and JavaScript of a plugin in WordPress so that on any page you just want to be loaded and used, I suggest using the following plugins.

    • WordPress Assets manager, dequeue scripts, dequeue styles
    • gonzales wp
    • Deactivate Plugins Per Page

    But if you want to write a condition that you can manage, it means a specific plugin only when you want it to work like a specific page. For this you need to know the exact name of the plugin and then do it using a plugin management function.

    Login or Signup to reply.
  2. I wrote this code and tested it, it worked properly.

    In this code, I first check the post ID, whether page or post or any other type of post.

    Then I disable all plugin styles and scripts and delete the class that is attached to the body

    Finally, I remove a new element created in a class to display the plugin root.

    Put this code in the functions.php file

    function disble_shopwp_pages()
    {
    
    
        $post_id_array = array(
            218, 433, 71, 2066, 825, 7, 2009, 2284, 420, 2402, 2394,
        );
    
        if (in_array(get_the_ID(), $post_id_array)) {
    
            return true;
        }
    
    
    }
    
    function remove_wpshopify()
    {
    
    
        if (disble_shopwp_pages()):
    
            wp_dequeue_style('shopwp-styles-frontend-all');
            wp_deregister_style('shopwp-styles-frontend-all');
            wp_dequeue_script('shopwp-runtime');
            wp_dequeue_script('shopwp-vendors-public');
            wp_dequeue_script('shopwp-public');
    
    
        endif;
    }
    
    add_action('wp_enqueue_scripts', 'remove_wpshopify', 9999);
    
    
    function wpshopify_body_class($classes)
    {
    
        if (disble_shopwp_pages()) {
            unset($classes[array_search('shopwp', $classes)]);
        }
    
        return $classes;
    }
    
    add_filter('body_class', 'wpshopify_body_class', 999, 2);
    
    function remove_shopwp_root_elements()
    {
    
    
        if (disble_shopwp_pages()) {
    
            echo '<script>
                        jQuery(document).ready(function () {
                                jQuery("#shopwp-root").remove();
                        });
                      </script>';
    
        }
    }
    
    add_action('wp_footer', 'remove_shopwp_root_elements');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search