• Hi
    Is it possible to disable loading the style sheet on every page, I know it’s only small but seems a bit pointless when the form is just on one page?

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Guido

    (@guido07111975)

    Hi,

    This has been asked before and I always thought it wasn’t possible… but after a new search in the codex I notice this check… so I will do a few tests and keep you informed.

    Guido

    Thread Starter darrencss

    (@darrencss)

    OK, thanks

    Plugin Author Guido

    (@guido07111975)

    Hi,

    I’ve found a solution but it should also load my stylesheet if form is displayed as widget in a sidebar. Until now I’ve only found this:

    
    // enqueues plugin scripts
    function vscf_scripts() {	
    	global $post;
    	if(!is_admin())	{
    		if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'contact') ) {
    			wp_enqueue_style('vscf_style', plugins_url('/css/vscf-style.css',__FILE__));
    		} elseif ( is_active_widget( false, false, 'vscf-widget' ) ) {
    			wp_enqueue_style('vscf_style', plugins_url('/css/vscf-style.css',__FILE__));
    
    		}
    	}
    }
    add_action('wp_enqueue_scripts', 'vscf_scripts');
    

    But there’s a problem, with this code it will always load my stylesheet if my widget is set, somewhere at your site.

    So I will try to find a solution for this.

    Guido

    Thread Starter darrencss

    (@darrencss)

    Hey thanks,
    I am not using the widget anywhere so this solution works for me.

    Thread Starter darrencss

    (@darrencss)

    Actually, I have tested this on a live site and seems to have gone wrong – adding extra input boxes.

    So I have reverted back to the original for now.

    On one site it worked fine though, maybe because the default shortcode [contact] was in use?

    The site that went wrong had the modified code [contact email_to=”xxx” hide_subject=”true”]

    • This reply was modified 8 years, 11 months ago by darrencss.
    Plugin Author Guido

    (@guido07111975)

    Hi,

    The extra “input boxes” are the 2 honeypot fields which should be hidden.. meaning plugin stylesheet wasn’t loaded.

    You should not modify my code itself, it should work. Also when having attributes in your shortcode.

    Guido

    Plugin Author Guido

    (@guido07111975)

    Hi,

    I have asked on another forum wether it’s possible to determine if my widget is present on the current page or not, but it seems impossible to determine this (easily) in current WordPress.

    Guido

    Thread Starter darrencss

    (@darrencss)

    OK, I have now have it working; I am just using the standard [contact] shortcode to keep things simple.

    I think disabling the style sheet for when a widget is not present is probably overkill. If anyone wants to use this function I think they will be not too worried about it?

    For me, because I only have one contact form on a site with over 300 pages, it made sense to reduce the load where possible.

    Thanks again for your support.

    Plugin Author Guido

    (@guido07111975)

    Hi,

    You’re welcome.

    With this function it will always load stylesheet in case my widget is set anywhere on a site. So that’s why this function is not good enough to add in a new plugin version yet.

    Guido

    Thread Starter darrencss

    (@darrencss)

    Hi
    It looks like latest update has broken this solution?

    Plugin Author Guido

    (@guido07111975)

    Hi,

    I did not add this in new version, sorry. Because I didn’t find a proper solution for the widget yet. So you should add it again manually.

    By the way, plugin stylesheet is tiny so I cannot imagine page load will be worse because of this file.

    Guido

    Plugin Author Guido

    (@guido07111975)

    Hi Darren,

    Again an update, but still without your request. Did some work on the From header, please check this thread.

    By the way, I ran into another issue regarding your request.. Besides shortcode being present on page or in a widget, there should also be a check if shortcode is included in a template file using do_shortcode.

    Guido

    @guido, try the following code. I think it should work. It accounts for both shortcodes and widgets.

    
    // enqueues plugin scripts
    function vscf_scripts() {
    	$current_post         = get_post( get_the_ID() );
    	$current_post_content = $current_post instanceof WP_Post ? $current_post->post_content : '';
    	$is_widget_active     = is_active_widget( false, false, 'vscf-widget', true );
    	$has_shortcode        = has_shortcode( $current_post_content, 'contact' );
    
    	if ( ( $is_widget_active || $has_shortcode ) && ! is_admin() ) {
    ) {
    		wp_enqueue_style( 'vscf_style', plugins_url( '/css/vscf-style.css', __FILE__ ) );
    	}
    }
    add_action('wp_enqueue_scripts', 'vscf_scripts');
    

    Andy

    • This reply was modified 8 years, 5 months ago by Andy Fragen.
    • This reply was modified 8 years, 5 months ago by Andy Fragen.
    Plugin Author Guido

    (@guido07111975)

    Hi @afragen / Andy,

    Sorry for the very late reply, I didn’t notice it before.

    The is_active_widget() will return true if the widget is active on your site… somewhere. So if you have set the contact widget somewhere on your site, plugin stylesheet will be loaded on every page. That was exactly the problem I ran into myself.

    Guido

    Not to worry. I was just trying to help out. Sorry it didn’t work.

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Merge Style.css’ is closed to new replies.