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.

I just installed the wptouch plugin for auto-styling my blog in mobile devices. How can I style a certain element on my page to be hidden when this view is active?

I.e., in particular, on my blog Under My Hat, I have a WP Follow Me plugin which behaves rather annoyingly on mobile devices, which is why I'd like to hide it. But other elements are custom tables and source code examples that I would like to style differently.

share|improve this question
add comment

1 Answer

I use the following code to intrude myself into WPTouch until I buy a licence :)

Better than simply hiding other plugins is disabling everything you can of it.
And the visitor gain less (and unnecessary) elements to load in their device.

The insert_scripts is pretty straight forward, adjust to your needs.

The remove_scripts I did from a fast analysis of Follow Me code.
To check if you really got rid of the plugin scripts, test using Safari with its Activity Monitor and User Agent simulator (it's perfect on Macs, donnow in Wins).

edit: my original/working script have these calls inside the remove_scripts:

remove_action('wp_head', 'add_css');
wp_deregister_script( 'jqplot' ); 

And right now, re-reading this answer, I think that add_action('wp_head','function'); being used to remove_action('init','function'); may not be correct, would be glad to have a peer review...

<?php
/*
Plugin Name: WPTouch Retouch
Plugin URI: http://wordpress.stackexchange.com/q/52026/12615
Description: Add custom scripts to enhance WPTouch and remove WP Follow Me scripts
Version: 1.0
*/

add_action('init', 'wpse_52026_process_wptouch');

function wpse_52026_process_wptouch(){
    if (function_exists('bnc_wptouch_is_mobile')) {
        if(bnc_wptouch_is_mobile()) {
            add_action('wp_head', 'wpse_52026_remove_plugin_scripts', 1);
            add_action('wp_head', 'wpse_52026_insert_wptouch_scripts');
        }
    } 
}

function wpse_52026_remove_plugin_scripts() {
    remove_action('init', 'wp_followme_scripts');
    remove_action('init', 'followme_admin_warnings');
    remove_action('wp_head', 'wp_followme_css');
    remove_action('get_footer', 'show_followme');
    //wp_deregister_script( 'if-there-were-a-registered-script' ); 
}

function wpse_52026_insert_wptouch_scripts() {
    $today = 'Valencia : Spain : '. date("d/m/Y");
    echo <<<HTML
    <style type="text/css">
        body {background:url('http://www.example.com/wp-content/uploads/pattern.png') fixed !important;}
    </style>
    <script type="text/javascript">
    jQuery(document).ready( function($) {
        $("div.content").prepend('<div style="margin-left: 13px;"><h4>Site Description</h4><small>{$today}</small></div>');
    });
    </script>
HTML;
}

Attention to the PHP Heredoc syntax <<<HTML

[important update]
When first answered, I forgot an essential part: this has to run as a plugin.

Obviously, putting the code into the desktop theme functions.php file doesn't do the job. And hacking other plugins is kind of pita: at each update you have to re-hack...

[references on how to remove other plugins' styles and scripts] http://wordpress.stackexchange.com/a/40833/12615
Is it possible to stop selected plugins from loading on certain template pages?
How to dequeue a script?
http://wordpress.stackexchange.com/a/27983/12615
http://wordpress.stackexchange.com/a/13331/12615

share|improve this answer
    
Excellent, I wished I could give you a double upvote for the Safari-hint. One question though, where would I place this script? If in the Follow-me code, would WPTouch already be loaded? Or when in the WPTouch code, would the follow-me already be loaded? Or is there some general post-addscripts hook I can use? –  Abel May 14 '12 at 6:47
    
Sorry mate, I forgot an essential part of the code :/ It has to run as a plugin. I'll update my answer with a plugin header and this extra info. –  brasofilo May 14 '12 at 10:47
add comment

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.