Home › Forums › Best Commerce › Dequeue and enqueue css
- This topic is empty.
-
AuthorPosts
-
April 18, 2019 at 9:23 am #11421AnonymousInactive
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’, ?
April 18, 2019 at 9:33 am #11422AnonymousInactiveShould 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');
April 19, 2019 at 10:50 am #11431Axle SupportModeratorHi @johnnyd,
Have you changed it through child theme? Also, have you done it using
wp_enqueue_scripts
hook?April 19, 2019 at 5:23 pm #11462AnonymousInactiveI 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.April 22, 2019 at 6:54 am #11479Axle SupportModeratorHi @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.
April 22, 2019 at 8:47 am #11483AnonymousInactiveI 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
April 22, 2019 at 8:58 am #11486Axle SupportModeratorHi @johnnyd,
Yes, simply change the location and it will work.
April 22, 2019 at 8:59 am #11487AnonymousInactiveAlright, thank you mate, I will test it and update the topic
April 22, 2019 at 10:02 am #11488AnonymousInactiveIt 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' );
April 22, 2019 at 10:45 am #11490Axle SupportModeratorHi @johnnyd,
You do not need to add
.css
extension. Simply use it like thiswp_enqueue_style( 'font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/css/all.min.css', '', '4.7.0' );
-
AuthorPosts
- The topic ‘Dequeue and enqueue css’ is closed to new replies.