WordPress.org

Ready to get started?Download WordPress

Forums

Another WordPress Classifieds Plugin
[resolved] Add support for wp_enqueue_scripts for styles too (2 posts)

  1. ahuggins
    Member
    Posted 2 years ago #

    I also see this being helpful for those that want to control which pages scripts and stylesheets are loaded on.

    Here's the code that needs to be changed, I left in the old function so you could see what needs to be changed:

    function awpcp_addcss() {
    	//$awpcpstylesheet="awpcpstyle.css";
    	//$awpcpstylesheetie6="awpcpstyle-ie-6.css";
    	//echo "\n".'<!--[if lte IE 6]><style type="text/css" media="screen">@import "'.AWPCP_URL.'css/'.$awpcpstylesheetie6.'";</style><![endif]-->
    	//		 ';
    	// load custom stylesheet if one exists in the wp-content/plugins directory:
    //	if (file_exists(WP_PLUGIN_DIR.'/awpcp_custom_stylesheet.css')) {
    //	    echo "\n".'<link rel="stylesheet" type="text/css" media="screen" href="'.WP_PLUGIN_URL.'/awpcp_custom_stylesheet.css" />';
    //	}
    
    }
    
    function awpcp_enqueue_style(){
    	wp_register_style('awpcp_styles', AWPCP_URL.'css/awpcpstyle.css');
    	wp_enqueue_style('awpcp_styles');
    	global $is_IE;
    	if( $is_IE ) {
    		wp_register_style('awpcp_ie6_styles', AWPCP_URL.'css/awpcpstyle-ie-6.css');
    		wp_enqueue_style('awpcp_ie6_styles');
    	}
    	if (file_exists(WP_PLUGIN_DIR.'/awpcp_custom_stylesheet.css')) {
    		wp_register_style('awpcp_custom_styles', WP_PLUGIN_DIR.'/awpcp_custom_stylesheet.css');
    		wp_enqueue_style('awpcp_custom_styles');
    	    //echo "\n".'<link rel="stylesheet" type="text/css" media="screen" href="'.WP_PLUGIN_URL.'/awpcp_custom_stylesheet.css" />';
    	}
    }
    add_action('wp_enqueue_scripts', 'awpcp_enqueue_style');

    This conditionally loads the IE styles for IE, a little more work would be needed to load only for IE6, but it shouldn't be too bad. It also enqueues the styles for custom_styles and does it conditionally, so only for those that have that file.

    Let me know if you run into any issues. Would appreciate if you could make these changes.

    http://wordpress.org/extend/plugins/another-wordpress-classifieds-plugin/

  2. awpcp
    Member
    Plugin Author

    Posted 2 years ago #

    We'll try it out and if there are no conflicts, we'll go for it. IE6 is evil. :) We're trying to phase it out.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic