Puck Puck - 1 month ago 13
CSS Question

wp_enqueue_style Does Not Behave As Documented

I have the following written in a driver:

add_action( 'wp_enqueue_scripts', 'add_css_file' );
function add_css_file()
{
// Tried this prior:
// $path = ABSPATH . "/wp-content/plugins/this_plugin/css/";
// wp_register_style( 'css_file', $path.'css_file.css' );

wp_register_style( 'css_file', 'http://subdomain.mysite.com/wp-content/plugins/this_plugin/css/css_file.css' );
wp_enqueue_style( 'css_file' );
}


The string "css_file" does not appear in the View Source HTML and the CSS rules defined therein do not take effect.

Answer

The problem for me lay in the fact that I am modifying the Admin screen rather than the display of a Page or Post to viewers.

Replace:

 wp_enqueue_script(...)

With:

 admin_enqueue_script(...)

Best of luck.

Comments