WordPress.org

Forums

Trouble with wp_enqueue_style (3 posts)

  1. Scott Fennell
    Member
    Posted 4 years ago #

    Hi,

    I have echoed out the URL variable and confirmed that it is correct. What am I missing here? The following code is in my main plugin file:

    add_action('wp_print_styles', 'add_my_stylesheet');
    function add_my_stylesheet() {
    	$myStyleFile = WP_PLUGIN_URL . '/coupon_code_chocolate_factory/layout/sjf_coupon_styles.css';
    	if ( file_exists($myStyleFile) ) {
    		wp_register_style('myStyleSheets', $myStyleFile);
    		wp_enqueue_style( 'myStyleSheets');
    	}
    }
  2. Scott Fennell
    Member
    Posted 4 years ago #

    Hmmm ... to continue debugging, I tried calling it with "admin_menu" instead of "wp_print_styles" and it worked!

  3. Scott Fennell
    Member
    Posted 4 years ago #

    Okay, I don't know if this is the best way to do this, but now it works fine:

    if(isset($_GET['page'])){
    	if(($_GET['page'])=='Coupon-Factory'){
    		add_action('admin_menu', 'add_my_stylesheet');
    		function add_my_stylesheet() {
    			$myStyleUrl = WP_PLUGIN_URL . '/coupon_code_chocolate_factory/layout/sjf_coupon_styles.css';
    			$myStyleFile = WP_PLUGIN_DIR . '/coupon_code_chocolate_factory/layout/sjf_coupon_styles.css';
    			if ( file_exists($myStyleFile) ) {
    				wp_register_style('myStyleSheets', $myStyleUrl);
    				wp_enqueue_style( 'myStyleSheets');
    			}
    		}
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.