i enqueue wp files for fontawesome and main.js
but fontawesome shows 403 error and main.js returns 404 error although both files exists in server
and it works on local host
but not on server
below is functions.php
function banking_files(){
//css
wp_enqueue_style('google-fonts','https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@300;400;500;700&display=swap');
wp_enqueue_style('google-fonts2','https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;600;800&display=swap');
wp_enqueue_style('google-fonts2','https://fonts.googleapis.com/css2?family=Oswald:wght@300;400;500&display=swap');
//wp_enqueue_style('bootstrap',get_stylesheet_uri().'/assets/css/bootstrap.css',array(),'4.0','all');
wp_enqueue_style('bootstrap',get_template_directory_uri().'/assets/css/bootstrap.css',array(),'4.0','all');
wp_enqueue_style('font-awesome','https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css');
wp_enqueue_style('slick-theme','https://cdn.jsdelivr.net/gh/kenwheeler/[email protected]/slick/slick-theme.css');
wp_enqueue_style('slick-css','https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.css');
wp_enqueue_style('custom',get_template_directory_uri().'/assets/css/style.css',array(),microtime(),'all');
wp_enqueue_style('banking_main_styles',get_stylesheet_uri(),array(),microtime());
//js
wp_enqueue_script('jquery');
wp_enqueue_script('boot-popper','https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js');
wp_enqueue_script('boot-js','https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js');
wp_enqueue_script('fontawesome-js','https://kit.fontawesome.com/a076d05399.js');
wp_enqueue_script('slick-js','https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js');
wp_enqueue_script('main-js',get_template_directory_uri().'./assets/js/main.js',array(),microtime(),true);
}
add_action('wp_enqueue_scripts','banking_files');
error screenshot in console
any help will be appreciated ..thanks
2
Answers
The request for fontawesome returns a 403 because for whatever reason fontawesome won’t accept requests from the server your website is hosted on. Status 403 means forbidden. Copy it, save it locally and reference that instead.
Your main-js returns a 404 because you’re trying to use a relative path, which wp_enqueue_script doesn’t like.
get_template_directory_uri().'/assets/js/main.js'
is the correct way to retrieve the path, omitting the extra period.If I’m not mistaking, any fontawesome hosted outside the fontawsome (eg: cloudfare) website in non-official. You have to go through the proper request from the start section on their website https://fontawesome.com/start. Any non-official hosting is prone to problem (eg: legal action, termination of service)
The
4.7
version isn’t the youngest, we’re now at5.15.3
public and6.0.0
pro.It seems you’re trying to load 2 different version and are doing it so without specifying any crossorigin attributes
crossorigin="anonymous"
, which is apparently required.crossorigin="anonymous"
attribute. (see the following snippet).Everything has been tested and is working locally and online.