Disable pluggins only in mobile version

  • Mandado

    #7694

    Hello,

    Is it possible to deactivate plugins only for the mobile version? I have an upper bar for subscriptions to my newsletters but I would like to disable it when people is using the mobile version of the website. How could I do it?

    Thanks!

    Anonymous

    #39052

    You can use deactivate_plugins() function with child theme to deactivate one or more plugins. Let us know when you have a child theme for Graphene Neo in your site.

    Mandado

    #39053

    I have set up the child theme, could you give me an example of the function code for one plugin? If I want to deactivate 2 I just put the function two times?

    There is 2 that I am considering deactivating: SEO Facebook Comment and ViperBar.

    http://wordpress.org/plugins/seo-facebook-comments/

    http://wordpress.org/plugins/viperbar/

    Admin

    Syahir Hakim

    #39054

    It’s rather difficult (if not impossible) to selectively disable plugins from within a theme. This is because a theme is loaded after all the plugins have been loaded. Therefore, at best you will see the plugin still active on first view of the mobile theme, and then deactivated on subsequent views.

    And of course, you will have to activate the plugins again whenever the desktop theme is viewed. Once this happens, the above will repeat again. And it’s very likely that both mobile and desktop view of your site can be viewed at the same time (or at least within very little time difference) by two or more visitors.

    A workaround to this limitation is to restart all of WordPress’ loading and processing immediately after the plugins deactivation, but this will reduce performance somewhat as the first round of processing is effectively thrown away to restart again. There is also no telling what effect that will have on caching plugins if you use any.

    It’s perhaps better to just hide the output of the plugins by using the mobile theme’s Custom CSS feature.

    Prasanna, if you have suggestions on how to make it work, I’m all ears.

    Admin

    Syahir Hakim

    #39055

    Actually, on further testing, it appears that restarting all of WordPress’ loading and processing immediately after plugins deactivation have no performance cost whatsoever (at least on my limited testing condition). It could be that the performance cost induced for restarting the processes is compensated by the performance advantage of not loading and processing the deactivated plugins later on.

    Anonymous

    #39056

    I’m not really sure about deactivate_plugins() function. But one of my friends wanted to remove facebook comments from his mobile site. I just removed the filter and it worked without any compromise in the performance.

    remove_filter('comments_array', 'facebook_comments');
    Admin

    Syahir Hakim

    #39057
    Quote:
    I’m not really sure about deactivate_plugins() function. But one of my friends wanted to remove facebook comments from his mobile site. I just removed the filter and it worked without any compromise in the performance.

    remove_filter('comments_array', 'facebook_comments');

    Yeah, that’s analogous to using Custom CSS to hide the output, but in a cleaner way with performance advantage. But you’ll still have to figure out which filters/actions to remove, and which scripts and stylesheets to dequeue. That can be easy for some plugins, but can also be tedious and difficult for more complex plugins.

    Using activate_plugins() and deactivate_plugins(), we can effectively list all plugins and let the user tick which one to enable and disable for the mobile theme.

    Anonymous

    #39058
    Quote:
    Using activate_plugins() and deactivate_plugins(), we can effectively list all plugins and let the user tick which one to enable and disable for the mobile theme.

    Yup, that feature would be great!

    Mandado

    #39059

    I tried putting the line

    remove_filter('comments_array', 'facebook_comments');

    in my child theme functions file but it didn’t change anything.

    Mandado

    #39060

    How could I use activate_plugins() and deactivate_plugins() functions?

Viewing 10 posts - 1 through 10 (of 19 total)

  • 1
  • 2
  • You must be logged in to reply to this topic.