Dequeue and enqueue css

Home Forums Best Commerce Dequeue and enqueue css

  • This topic is empty.
Viewing 10 posts - 1 through 10 (of 14 total)
  • Author
    Posts
  • #11421
    Anonymous
    Inactive

    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
    Anonymous
    Inactive

    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
    Anonymous
    Inactive

    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
    Anonymous
    Inactive

    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

    #11486
    Axle Support
    Moderator

    Hi @johnnyd,

    Yes, simply change the location and it will work.

    #11487
    Anonymous
    Inactive

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

    #11488
    Anonymous
    Inactive

    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' );

    #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.