Font display is malfunctioning within a WordPress theme

I am currently in the process of updating my online portfolio and have encountered an issue with @font-face. Initially, everything was working perfectly fine as I implemented it in static HTML. However, when converting the static HTML into a dynamic Wordpress theme, the @font-face functionality stopped working.

In the static version, I had placed the font files in a folder named "fonts" within the main directory where index.html is located. The font was declared at the beginning of the CSS file like this:

@font-face {
font-family: 'MaidenOrange';
src: url('fonts/MaidenOrange-webfont.eot');
src: url('fonts/MaidenOrange-webfont.eot?#iefix') format('embedded-opentype'),
     url('fonts/MaidenOrange-webfont.woff') format('woff'),
     url('fonts/MaidenOrange-webfont.ttf') format('truetype'),
     url('fonts/MaidenOrange-webfont.svg#MaidenOrangeRegular') format('svg');
font-weight: normal;
font-style: normal;
}

The font was then called using font-family: MaidenOrange; throughout the rest of the CSS file.

When transitioning to Wordpress, I copied the entire stylesheet and moved the "fonts" folder into the theme directory. However, this approach did not work initially, which led me to research and discover a possible issue with absolute vs. relative paths. As a result, I modified the @font-face declaration in the Wordpress Theme stylesheet as follows:

@font-face {
font-family: 'MaidenOrange';
src: url('<?php bloginfo('template_directory'); ?>/fonts/MaidenOrange-webfont.eot');
src: url('<?php bloginfo('template_directory'); ?>/fonts/MaidenOrange-webfont.eot?#iefix') format('embedded-opentype'),
     url('<?php bloginfo('template_directory'); ?>/fonts/MaidenOrange-webfont.woff') format('woff'),
     url('<?php bloginfo('template_directory'); ?>/fonts/MaidenOrange-webfont.ttf') format('truetype'),
     url('<?php bloginfo('template_directory'); ?>/fonts/MaidenOrange-webfont.svg#MaidenOrangeRegular') format('svg');
font-weight: normal;
font-style: normal;

Unfortunately, even after making these adjustments, the issue persists and my theme continues to display Arial instead of the desired font. Despite extensive research efforts, I have yet to find a solution. Any assistance or guidance on this matter would be greatly appreciated!

Answer №1

It appears that there might be a misunderstanding in your message. Having PHP code in a CSS file is not advisable. Consider relocating the second block of code to your theme's header.php file, enclosed within <style> tags.

Alternatively, you could transfer your fonts folder to the root directory of your website and utilize site-absolute paths, such as:

src: url('/fonts/MaidenOrange-webfont.eot');

Answer №2

It is important to note that PHP tags cannot be used in a CSS file unless your server has been configured to allow it. Providing the rendered style.css may assist in pinpointing the issue at hand.

Relative paths typically function correctly, so incorrect paths are unlikely to be the cause of the problem unless they have been inaccurately specified.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display subpages of WordPress site in a dropdown menu on the navigation bar

Currently in the process of converting an HTML website to Wordpress, I am encountering a challenge. The issue lies in my attempt to add a drop-down feature to the navigation list using the wp_list_pages tag. As it stands, when hovering over the "products" ...

Removing CSS styles using jQuery when the page loads

Check out this jsFiddle before I ask my question: http://jsfiddle.net/AxGHA/3/ I am looking for a way to remove the float: left; styling from the H2 and P tags if there is no image in the div using jQuery. Any suggestions on how to achieve this? Apprecia ...

Viewport Scrolling and Pinching on Safari Browser with Bootstrap 4 Website Still Possible

I have experimented with using Bootstrap 4 skeleton and have tested different viewport meta tags. The built-in Bootstrap viewport meta tag I used is: <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no&quo ...

Discover the secret to halting a CSS animation precisely on the final nth-child in CSS3

I have encountered some difficulty in stopping a crossfade animation on the last nth-child element. Although I am aware of using animation-fill-mode: forwards, implementing it in different places such as in the initial .crossfade declaration did not yield ...

Ways to customize the size of a radio button with CSS

Is it possible to adjust the size of a radio button using CSS? ...

Say goodbye to my HTML5 creations

I am currently working on an HTML5 grid project that involves implementing a rectangle select tool for use within the grid. Everything is going smoothly, except for the fact that when I attempt to use the rectangular select tool, the grid disappears from t ...

What is the CSS code to modify the color of an SVG ::marker?

I am looking to change the color of an SVG li::marker based on the font color. I attempted using fill="currentColor" but it did not work as expected. Any suggestions on how to resolve this? li::marker { content: url("data:image/svg+xml,% ...

When the maximum width of an image within a flexbox is set, the aspect ratio may not be preserved

My goal is to use flex to easily center an img vertically inside a div, however, the behavior differs across various browsers. .flex-container { display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: fle ...

Tips for reducing the impact on performance caused by cookie consent code

Experimenting with basic HTML to analyze the impact of cookie consent code. <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="description" content="determine page l ...

Chrome experiencing conflicts with backstretch when using multiple background images

In order to dynamically apply fullscreen background images in a WordPress site, I am utilizing Backstretch.js along with a custom field. Everything is functioning properly for the body's background image. However, there seems to be an issue with anot ...

What is the method for initiating a radial gradient from the middle of the pie chart?

In my pie chart with grid lines, I have successfully implemented a radial gradient. However, the issue is that there is a separate gradient for each pie slice. What I really want is a single gradient originating from the center of the entire pie chart. I ...

How to create a stunning pixel pattern overlay on a website section

I've been exploring how to add a pixel pattern overlay onto a website section similar to what's done on this site: (over the background video image at the top and the image in the bottom section). I'm sure it's a simple process, I jus ...

Adjusting the height of the Owl Carousel div to enhance image hover effects

Seeking help with implementing a hover effect on an img within an Owl Carousel div. I have applied a simple CSS transition to the Owl Carousel container div, but the Carousel is automatically setting a standard height. Images included for reference. I have ...

The #skrollr-body element causes all mobile content to disappear

Currently, I am utilizing Skrollr.js for parallax effects and you can find it here: https://github.com/Prinzhorn/skrollr. At the beginning of development, I made sure to test this on mobile to ensure it functioned properly. Initially, everything was workin ...

Changing the bootstrap popover location

I'm looking to customize the position of a Bootstrap popover that appears outside of a panel. Here's my setup: HTML: <div class="panel"> <div class="panel-body"> <input type="text" id="text_input" data-toggle="popover ...

Combining SQL inner joins within the WordPress environment using a WHERE clause to match specific IDs

Hey there! I'm facing a little issue. My ID is '28' and I only want to display the first object where this ID is present. How can I achieve this with SQL? WordPress SQL: $rows = $wpdb->get_results( "SELECT hotels.id,hotels.hote ...

Create a hyperlink to the tabbed navigation menu

I want to create links to the tabbed menu for my website. The homepage has 4 categories: car, van, truck, and special, each of which leads to the portfolio page. The portfolio page includes a simple filtered tabbed menu structured like this: <ul id="f ...

How to align Material UI's <TextField> component in the middle of a React project

I'm struggling to align two <TextArea> components using material ui and React. Both of them are contained within the same <div> and share the same className. Despite trying to apply the !important rule in CSS, I haven't been able to ...

Turn off hover effect using solely CSS

This is my first time posting on stackoverflow, so please excuse me if I overlook something obvious. I tried searching for a solution beforehand but couldn't find one that seemed relevant. In the following jsfiddle example, I have a div that acts as ...

How can I place a new ThreeJS child element at the front and center of a scene?

I have been working on a webpage that is inspired by the CSS3D molecules sample from ThreeJS's library. You can check out the original sample here. In my project, I am dynamically creating new nodes (atoms) and attaching them to existing nodes. Once ...