Home > Net >  Call fonts inside css for wordpress css
Call fonts inside css for wordpress css

Time:10-06

I'm creating a custom theme and calling a font inside a theme css.

This is my functions PHP,

function load_stylesheets(){
    wp_register_style('mycss', get_template_directory_uri() . '/assets/css/mycss.css', array()
        , false, 'all');
    wp_enqueue_style('mycss');
}

add_action('wp_enqueue_scripts', 'load_stylesheets');

And in mycss.css has these fonts

@font-face {
    font-display: swap;
    font-family: "myfont";
    src: url('fonts/myfont.eot');
    src: url('fonts/myfont.eot?#iefix') format('eot'),
    url('fonts/myfont.woff2') format('woff2'),
    url('fonts/myfont.woff') format('woff'),
    url('fonts/myfont.ttf') format('truetype'),
    url('fonts/myfont.svg#icomoon') format('svg');
    font-weight: normal;
    font-style: normal;
}

And even though I have \wp-content\themes\mytheme\assets\fonts\myfont.woff2 I'm getting a not found error for the file,

net::ERR_FAILED 200

Is there a way to fix this and I need to call background images in css and hope I can apply the same fix. Sorry if this is simple but I'm bit new to wordpress.

CodePudding user response:

mycss.css

@font-face {
    font-display: swap;
    font-family: "myfont";
    src: url('../fonts/myfont.eot');
    src: url('../fonts/myfont.eot?#iefix') format('eot'),
    url('../fonts/myfont.woff2') format('woff2'),
    url('../fonts/myfont.woff') format('woff'),
    url('../fonts/myfont.ttf') format('truetype'),
    url('../fonts/myfont.svg#icomoon') format('svg');
    font-weight: normal;
    font-style: normal;
}
  • Related