CSS not loading inside sub directory - php

I am trying to load the css from a sub directory through index.php and have defined a constant AMIN_CSS ="http://localhost/gbl_admin/admin_css".
This being in the same directory loads the css:
<link href="<?php echo ADMIN_PAGE."/style.css"?>" type="text/css" rel="stylesheet">
but this one is in the sub directory:
<link href="<?php echo ADMIN_PAGE."/admin_css/style.css"?>" type="text/css" rel="stylesheet">
//constant decleration
define("SITEURL",'http://'.#$_SERVER['SERVER_NAME']."/");
define("ADMIN_PAGE",SITEURL."gbl_admin");
define("ADMIN_SCRIPTS",SITEURL."gbl_admin/admin_scripts");
define("ADMIN_CSS",SITEURL."gbl_admin/admin_css");
This one doesn't load!! How can i solve this?

The second link which you are referring is perceived as
http://localhost/gbl_admin/admin_css/admin_css/style.css
You can see that admin_css is repeated twice hence it is not able to load the CSS File. Hence the correct url should be as follows :
http://localhost/gbl_admin/admin_css/style.css

Related

Dynamic link in css stylesheet with PHP variable

I'm building a dynamic page template for wordpress (which means it has to work at least 4 different domain without changing anything like links etc.) and I added a custom css link like this:
<link type="text/css" rel="stylesheet" href="https://mywebsite.com/wp-content/themes/mytheme/css/page-food.css">
I can reach the server home in a variable like $home_path. Or the theme main folder like $theme_path. So is there any possible way to add the href a PHP variable?
I mean
<link type="text/css" rel="stylesheet" href="$theme_path/css/page-food.css">
just add php start and end tags there
<link type="text/css" rel="stylesheet" href="<?=$theme_path?>/css/page-food.css">
wordpress css call in daynamic path
<link href="<?php echo get_template_directory_uri(); ?>/css/fonts.css" type="text/css" rel="stylesheet">

How use absolute link in href header

I work on my website but I have a problem with the links in the href.
My CSS and javascript files are in this folder (in the root of my site):
assets/stylesheets/file_css.css
For now the links of my href looks like this:
<link rel="stylesheet" href="./assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="./assets/fonts/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="./assets/stylesheets/custom.css">
<link rel="stylesheet" href="./assets/stylesheets/media-queries.css">
I call it in all my php files with :
require_once __DIR__.'/layouts/header.php'
Problem:
When I want to create a folder to sort my files eg views (folder found at the root of my site)
Looks like views/test.php
All href don't work, console error :
test.php:10 GET http://localhost/mywebsite/views/assets/bootstrap/css/bootstrap.min.css
test.php:11 GET http://localhost/mywebsite/views/assets/fonts/font-awesome/css/font-awesome.min.css
test.php:12 GET http://localhost/mywebsite/views/assets/stylesheets/custom.css
In fact, my CSS aren't in views folder.
I tried many things
1 - <link rel="stylesheet" href="/assets/bootstrap/css/bootstrap.min.css">
error => test.php:10 GET http://localhost/assets/bootstrap/css/bootstrap.min.css
2 - <link rel="stylesheet" href="<?php echo __DIR__ ?>/assets/bootstrap/css/bootstrap.min.css">
error => test.php:10 Not allowed to load local resource: file:///C:/wamp/www/mywebsite/layouts/assets/bootstrap/css/bootstrap.min.css
I thought to put href="/mywebsite/assets/bootstrap/css/bootstrap.min.css" in the first link, it works locally but not on the server
I really need help, I start having too much PHP file at the root
Thank you

PHP - Including HTML from different folder

I am currently working on a admin backend and now want to move some pages into different folders (so I do not have all scripts in one folder).
Structure looks like this:
/
/theme/assets/...
/templates/head.php
/templates/foot.php
/top/index.php
/index.php
In head.php there are some stylesheets added like this
<link href="theme/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
This works fine for files in the root folder (e.g. index.php), but when I use the same head.php in /top/index.php it does not work because the path is wrong.
Is it somehow possible to properly include the stylesheets etc. while having the scripts in different folders?
Greetz,
Just specify the root identifier (/) at the beginning of the href attribute:
<link href="/theme/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
Try this,
<link href="../theme/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
In /top/index.php
OR
<link href="<?php echo $_SERVER['DOCUMENT_ROOT'] ?>/theme/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
This code can be used in any page. The $_SERVER['DOCUMENT_ROOT'] points to the root.
Use '../' to reference the folder above and work your way back.
e.g
<link href="../theme/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

How do I include a css file while creating a wordpress theme?

I'm trying to create a wordpress theme. After following some tutorials I've written this in my header.php
<link href="<?php bloginfo('stylesheet_url'); ?> " rel="stylesheet" type="text/css" media="screen" />
I have one CSS file, styles.css, in the same folder as the index.php. What I have id weirdly calling CSS from somewhere, but not from the style.css file. How do I make it call all its styles from the styles.css file?? Thanks : )
Might be a good idea to check the output of the bloginfo('stylesheet_url'); function (say, by echoing it out somewhere) and see wether it actually points to your stylesheet. You can always use bloginfo('stylesheet_directory'); and add a filename to link to another file in the same dir.

Where can i set the location of the css file in wordPress using php?

I am using wordpress and am trying to link to the stylesheet:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
It is not recognizing that link tag, because I think the bloginfo('stylesheet_url') part is not working correctly.
Where can I set the location of the stylesheet url in wordpress?
This is what should be specified:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" />
You are specifying correctly, make sure that you have put the CSS file in the root of your theme folder and the CSS file is named style.css
Another solution for those who want their stylesheet inside a subdirectory such as /css is to use bloginfo('template_url') instead of bloginfo('stylesheet_url')
Append the directory and stylesheet name inside the link href and outside the PHP tags
e.g.:
<link rel="stylesheet"
href="<?php bloginfo('template_url'); ?>/css/style.css"
media="screen" />
If (OOPS=='where did my background images go') { add relative path to image references in style sheet i.e. url(images/mybackground.jpg) becomes url(../images/mybackground.jpg) }

Categories