WordPress.org

Support

Support » Plugins and Hacks » Trouble with wp_enqueue_style

Trouble with wp_enqueue_style

  • Scott Fennell

    @scofennellgmailcom

    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');
    	}
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Scott Fennell

    @scofennellgmailcom

    Hmmm … to continue debugging, I tried calling it with “admin_menu” instead of “wp_print_styles” and it worked!

    Scott Fennell

    @scofennellgmailcom

    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');
    			}
    		}
    	}
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trouble with wp_enqueue_style’ is closed to new replies.