[Resolved] wp_enqueue_style – how to apply to a single page

Home Forums Support wp_enqueue_style – how to apply to a single page

This topic contains 3 replies, has 2 voices, and was last updated by  Leo 2 months, 2 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1194227

    Paul

    This code works well to link in the stylesheet style_test.css

    /* add link to stylesheet to the head section */
    add_action( 'wp_enqueue_scripts', function() {
    		$child_folder = trailingslashit( get_stylesheet_directory_uri() );
    		wp_enqueue_style( 'style', $child_folder . 'style_test.css' );
    	} );

    I want to only load it into the <head> for one page and have tried this:

    /* add link to stylesheet to the head section of page Test (id=337)
    add_action( 'wp_enqueue_scripts', function() {
    		if(is_single(337)) {
    		$child_folder = trailingslashit( get_stylesheet_directory_uri() );
    		wp_enqueue_style( 'style', $child_folder . 'style_test.css' );
    	}} );
    	*/

    But this stops it working altogether.
    Thank you, Paul

    #1194240

    Leo Customer Support
    #1194336

    Paul

    Perfect – thank you
    This code in functions.php works as epxected

    add_action( 'wp_enqueue_scripts', function() {
    		if(is_page('337')) {
    		$child_folder = trailingslashit( get_stylesheet_directory_uri() );
    		wp_enqueue_style( 'style', $child_folder . 'style_test.css' );
    	}} );
    #1194814

    Leo Customer Support
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.