WordPress Theme Files Not Linking - wordpress

In the last couple of days I have been creating a theme for my WordPress site, but suddenly I have experienced problems with it. The php files have stopped linking with the css files.
I have tried creating many different themes and have been getting the same result - a site that only looks like basic html.
Here is the coding I have been using to link them <link rel="stylesheet" href="styles.css" type="text/css" />
Does anyone have any ideas? Is anybody else having problems with their site?
P.s. Any help will be very much appreciated!! :D

You may want to try /styles.css, or ./styles.css. The "." means "up one directory level".
However, a better way to do it, would be to link to it like this:
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/styles.css" type="text/css" />
This creates a dynamic absolute path to the stylesheet.
As #rambu said below, wp_enqueue_style is the proper way to do this.
function add_my_style() {
wp_enqueue_style( 'my-styles', get_stylesheet_directory_uri().'/style.css' );
}
add_action( 'wp_enqueue_scripts', 'add_my_style' );

Related

preload link - wordpress and flatsome

I found so many different articles and tried to implement it, but I still can't get it working.
Google pagespeed recommends to preload few files, but I can't figure it out :/
I went ahead and updated my header.php
<head>
<!--custom preload -->
<link rel="preload" as="font" crossorigin="anonymous" href="https://allurehemp.com/allurehemp/assets/css/icons/fl-icons.woff2" >
<link rel="preload" as="style" crossorigin="anonymous" href="https://allurehemp.com/allurehemp/assets/css/fl-icons.css" >
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php wp_head(); ?>
</head>
And now i'm facing the following issue(s);
A preload for 'https://allurehemp.com/allurehemp/assets/css/fl-icons.css' is found, but is not used because the request credentials mode does not match. Consider taking a look at crossorigin attribute.
Any recommendation is appreciated =)
I realize this is quite delayed, but I just figured this out for my site. Maybe it will be helpful for others, if the OP doesn't need this anymore.
It's way simpler than I thought it would be. Below is what I did, and it worked. No more warning/penalty in PageSpeed Insights, and my performance score increased.
In your WP admin area/dashboard, go to Flatsome > Advanced > Global Settings (see screenshot below)
Screenshot of relevant Flatsome > Advanced > Global Settings area
Insert the following line into the 'Header Scripts' area:
<link rel='preload' href='//wp-content/themes/flatsome/assets/css/icons/fl-icons.woff2' as='font' type='font/woff2' crossorigin='anonymous'>
OTHER NOTES:
A. The link in my code snippet is relative to the site domain, so you don't need to change it and insert your domain or anything. The double slash forces the same security protocol as the origin site, so it should force load https if your site uses https (which it should).
B. This probably goes without saying, but you never know: If you're adding anything to the theme files, always use a child theme so your updates/changes don't get overwritten when you update your theme. Here's a great plugin I've used several times to create a child theme in WordPress: https://wordpress.org/plugins/child-theme-configurator/
C. The links you included in the in the header.php file didn't include the "type=" bit. I'm not certain, but this could have been the source of the problem for you.
D. I didn't add a preload link for the css file like you did because all my css is minified and combined. Also, that particular file is just a few lines anyway, so preloading likely won't make much of a difference.
Hopefully this helps! :)

Website not recognising stylesheet

I have what seems a very basic problem - my Wordpress site doesn't seem to be recognising the stylesheet. I've developed my own - first - WP theme, and it works fine on my local system. I've uploaded it to a free host to test it live, but it doesn't look like the stylesheet is being recognised.
The website is http://k1demo.byethost6.com , and in style.css I have imported the style sheet from my css folder which has been compiled from a LESS file.
Here is the code in my style.css file:
#import url("/css/styles.css");
And in my header.php the stylesheet is called as such from the head section:
<link rel="stylesheet" type="text/css" href="style.css" />
What am I missing?
What a mess. Currently in your code you are loading:
http://k1demo.byethost6.com/style.css
And it doesn't exist. You need to load:
http://k1demo.byethost6.com/wp-content/themes/K1/style.css
From then #import url("/css/styles.css"); looks at the [root]/css/ which leads to:
http://k1demo.byethost6.com/css/styles.css
It also doesn't exist.
Looks like your syntax is a little messed up...
<link rel="stylesheet" href="type="text/css" href="style.css" />
should be
<link rel="stylesheet" type="text/css" href="/css/style.css" />
The problem is, that you are trying to access the root of your theme folder, while in reality you are hitting the root of your website.
If you want to enqueue the stylesheet directly in the header.php do the following in your href="" to target any file in your theme folder:
<link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri(); ?>/style.css" />
But I strongly recommend you to let WordPress handle the enqueueing of your scripts and stylesheets in your functions.php.
function enqueue_styles() {
wp_enqueue_style( 'THEMENAME_style_css', get_template_directory_uri() . '/style.css', array(), '0.0.1' );
}
add_action( 'wp_enqueue_scripts', 'enqueue_styles' );
See the documentation of wp_enqueue_style:
https://developer.wordpress.org/reference/functions/wp_enqueue_style/
Note:
If you want your theme to support child themes, you can use get_stylesheet_directory_uri(); instead. This function will look in the child theme folder first, if it doesn't find the file, it will look in the parent theme folder.
The file path needed to be case sensitive, after changing that the css is now working. Very basic mistake...

How to change value stylesheet_url in wordpress?

I'm trying to modify a theme in wordpress and one thing I've stumbled upon is the way this theme is including a stylesheet file.
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
As I discovered stylesheet_url refers to the file named style.css in the root folder. How can I change the value of the stylesheet_url so that my stylesheet file in the css/ directory will be loaded instead of the default one?
you can put new css file path like this:
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_directory'); ?>/css/newstyle.css" />
and you can remove default css path if you don't need.
hope this helps you. All the best ;)
In function blog_info().
Here is the link to do this and also check this link and this.
You can also see an example here: Where is the value for Wordpress bloginfo('stylesheet_url') saved.

Choosing a specific stylesheet on a wordpress site when showing the site in a tab

This might be an easy question (hopefully) for you to answer. Not sure this is the right place to post the question, since I do not know if this is a CSS issue or a normal PHP programming issue (I know very little about PHP programming), so here goes:
I have a wordpress blog that uses three different stylesheets depending on the platform where the blog is viewed (web, ipad, iphone).
I recently made a tab on my Facebook page which opens the blog in an iframe, but it opens the web-style (default) stylesheet which is way too wide for the max width in Facebook tabs (810 px). However, the ipad-adapted stylesheet would work just fine there. I still wish to see the normal web-style view when I enter my web from outside Facebook, so it isn't an option to swith to the ipad-stylesheet as a default stylesheet.
Is there a way of passing on a parameter from the facebook tab: e.g. http://www.myblog.com/?style=facebook so that the site that shows inside the facebook tab uses the right stylesheet? I would think more people have had this problem but I have scoured the Internet for hours without knowing really what to look for. Somebody spoke about CSS selectors, but I have no clue as to how they work or how to implement them in a solution.
This is the code in the header.php that deals with the stylesheets:
<!-- Theme Styles -->
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/style.css" type="text/css" media="screen" />
<?php $disable_theme_features = of_get_option( 'disable_theme_features' ); if ($disable_theme_features['4'] == '0') { ?>
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/style-ipad.css" type="text/css" media="screen" />
<?php } if ($disable_theme_features['3'] == '0') { ?>
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/style-iphone.css" type="text/css" media="screen" />
<?php } ?>
Is there a way to make this happening without resorting to a complete makeover of the template? Any help would be greatly appreciated!! And sorry again if this is a noob question, that is because i am noob at PHP.
Thanks again!
You could use a PHP if statement. Such as if at the URL, then use this stylesheet.

Wordpress: How to override all default theme CSS so your custom one is loaded the last?

I have a problem where I've been able to include a custom css in the section of my wordpress theme with the following code:
function load_my_style_wp_enqueue_scripts()
{
wp_register_style('my_styles_css', includes_url("/css/my_styles.css"));
wp_enqueue_style('my_styles_css');
}
add_action('wp_enqueue_scripts','load_my_style_wp_enqueue_scripts');
But the order in the source code is as follows:
<link rel='stylesheet' id='my_styles_css-css' href='http://...folderA.../my_styles.css?ver=3.1' type='text/css' media='all' />
<link rel="stylesheet" id="default-css" href="http://...folderB.../default.css" type="text/css" media="screen,projection" />
<link rel="stylesheet" id="user-css" href="http://...folderC.../user.css" type="text/css" media="screen,projection" />
I want my_styles_css to be the last file to load, overriding default and user files. I've tried to achieve this by modifying wp_enqueue_style in different ways, but without any success. I've tried:
wp_enqueue_style('my_styles_css', array('default','user'));
or
wp_enqueue_style('my_styles_css', false, array('default','user'), '1.0', 'all');
I've seen some related questions without answer or with these last 2 methods that are still failing for me.
The function above is part of a plugin that I've got enabled in my wordpress installation.
The add_action function has a priority parameter that might help:
$priority
(int) (optional) How important your function is. Alter this to make your function be called before or after other functions. The default is 10, so (for example) setting it to 5 would make it run earlier and setting it to 12 would make it run later.
Default: 10
http://codex.wordpress.org/Function_Reference/add_action
Or you could directly link to your css in your header.php file rather than using wp_enqueue_style, and therefore place it exactly where you want.
Otherwise there seems to be an answer here: How to force wp_enqueue_style to display CSS at the very bottom of the head tag to override all CSS rules?
The correct way to add a stylesheet to your theme is by way of the wp_enqueue_style() function:
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
With $deps you specify which stylesheets should be loaded before your custom stylesheet.
What about add_action('wp_head','load_my_style_wp_enqueue_scripts');?
Use wp_head instead of wp_enqueue_scripts.
Why not edit the theme?
You can do this from the Dashboard
Appearance -> Editor -> header.php
Just add your css last.

Resources