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.
Related
I have a link to a style.css with version, which is updating each time after changing the file in my theme on server:
<link rel="stylesheet" type="text/css" media="all" href="http://example.com/wp-content/themes/twentythirteen/style.css?v=1477025590" />
Also, I can see another link to the same style.css in the source of code but with an old version which doesn't change automatically (it's a standart link of a theme):
<link rel='stylesheet' id='twentythirteen-style-css' href='example.com/wp-content/themes/twentythirteen/style.css?ver=2013-07-18' type='text/css' media='all' />
Is it normal? User should load a file twice or I can delete the second link somehow via functions.php?
Yes you need to check in your functions.php is there this css load
twice ? you can find wp_enque_style function over there.
Remove the css from there which loads twice it will solve your error
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...
A wordpress site of mine got hacked and there appears to be a favicon left by the hacker.
I cannot see it anywhere in the theme, there is no shortcut line in the header
<link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />
Any ideas where this file can be?
This is due to caching. You have to refresh it to remove the old icon.
Locate the favicon resource of your site by navigating to <YOUR SITE URL>/favicon.ico in your browser and do a hard refresh.
If the above doesn't work, try setting a new favicon by adding this to your current theme's header.php file.
<link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico?ver=new" /> and upload the new favicon to the appropriate location.
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' );
I'm a bit confused here.
I have a simple controller which loads a view. The view contains a form and links some CSS files. I don't really want to do ../../css/global.cssin my link tag. I want to use the base_url() method and then go /css/.
I know a friend uses the following:
<link href="{base_url}css/style.css" rel="stylesheet" type="text/css" />
However, I can't get that to work. He uses CodeIgniter 1.7 though, I'm using the latest (2.something) version. I'm new to CodeIgniter and I wanted to mess around with it, but I can't even link a simple CSS file :(
My view is in /logic/views/index.php, my css files are in /css/
Thanks a bunch.
I put my css files in the root directory and link them like this
<?php echo link_tag('css/forie.css'); ?>
<?php echo link_tag('css/reset.css'); ?>
<?php echo link_tag('css/main.css'); ?>
Using link_tag allows me to access them easily
I think your problem is that base_url is a function in ci 2+ so try this instead
<link href="<?php echo base_url() ?>css/style.css"
rel="stylesheet" type="text/css" />
It depends how you defined base_url if you did an ending slash otherwise just add a slash so
/css/style.css
You can use the URL helper to ease your URL woes :)
http://codeigniter.com/user_guide/helpers/url_helper.html
Usage
Load it up in your bootstrap
$this->load->helper('url');
And whenever you need something you can use
echo site_url("/css/style.css");
Or just assign it as a handy base url so you can use it wherever you want.
$base_url = site_url('/');
<link href="{$base_url}css/style.css" rel="stylesheet" type="text/css" />
<?php echo 'base url is' . $base_url?>
Note
Remember to define your proper base URL in the config file before using this method.
for CI 2+ you can add $this->load->helper('url'); before you load the view and then add
<link href="<?php echo base_url().'css/style.css';?>" rel="stylesheet" type="text/css" /> into your view file.