Dequeue and enqueue css

This topic contains 13 replies, has 2 voices, and was last updated by  Axle Support 1 month ago.

Viewing 10 posts - 1 through 10 (of 14 total)
  • Author
    Posts
  • #11421

    johnnyd
    Participant

    Hello guys, as I am trying to further optimize the website and theme I was trying to enqueue the fontawesome from cdnjs. I have added the following code in the functions file but it doesn’t seem to work. It does dequeue and de-register the font awesome css but it doesn’t seem to re-enqueue

    	wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/vendors/font-awesome/css/font-awesome' . $min . '.css', '', '4.7.0' );
    
    			//test dequeue-enqueue
    	wp_dequeue_style( 'font-awesome' );
    	wp_deregister_style( 'font-awesome' );
    	wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/css/all.min.css', array(), NULL, 'all');

    Should I remove the ,array(), and add the ‘.css’, ?

    #11422

    johnnyd
    Participant

    Should it be something like this?

    	wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/vendors/font-awesome/css/font-awesome' . $min . '.css', '', '4.7.0' );
    
    			//test dequeue-enqueue
    	wp_dequeue_style( 'font-awesome' );
    	wp_deregister_style( 'font-awesome' );
    	wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/css/all.min.css', '.css', '', '4.7.0');
    #11431

    Axle Support
    Moderator

    Hi @johnnyd,

    Have you changed it through child theme? Also, have you done it using wp_enqueue_scripts hook?

    #11462

    johnnyd
    Participant

    I am not using a child theme as I do not update the free version of bestcommerce. As I said above I used the wp_enqueue_style (not script as it’s a style).
    As I am using the original theme, and not a child should I just change the style path? I would also want to change the jquery path but I’m not sure if I am doing it correctly thus didn’t try it yet.

    #11479

    Axle Support
    Moderator

    Hi @johnnyd,

    We normally do not recommend to change the main theme file. However, you have already changed it. As you are changing main theme file, you can simply remove scripts/style you do not want to use and add your own scripts/style as per your wish.

    #11483

    johnnyd
    Participant

    I know it’s not recommended to change the main theme file, but in this case the theme editing was started before I was in charge of the project thus couldn’t revert back to the default files and re-edit everything. So instead of de-queue I just edit the file “location” from the theme folder to cdnjs?

    so in this case
    wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/vendors/font-awesome/css/font-awesome' . $min . '.css', '', '4.7.0' );

    instead of
    get_template_directory_uri() . '/vendors/font-awesome/css/font-awesome' . $min .

    I will add the cdnjs link
    https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/css/all.min.css

    • This reply was modified 1 month ago by  johnnyd.
    #11486

    Axle Support
    Moderator

    Hi @johnnyd,

    Yes, simply change the location and it will work.

    #11487

    johnnyd
    Participant

    Alright, thank you mate, I will test it and update the topic

    #11488

    johnnyd
    Participant

    It seems it’s working though after the path (url) we should add a coma so it should be something like this. In the beginning I didn’t add the coma before ‘.css’ and when trying to clear cache I was getting an error 500.

    wp_enqueue_style( 'font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/css/all.min.css', '.css', '', '4.7.0' );

    • This reply was modified 1 month ago by  johnnyd.
    #11490

    Axle Support
    Moderator

    Hi @johnnyd,

    You do not need to add .css extension. Simply use it like this

    wp_enqueue_style( 'font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/css/all.min.css', '', '4.7.0' );

Viewing 10 posts - 1 through 10 (of 14 total)

The topic ‘Dequeue and enqueue css’ is closed to new replies.