Adding css & js files to wordpress theme - php

In order to add Css & Js files to my website pages, I wanna add the following code to the functions.php file:
function cssjsloading(){
wp_enqueue_style('bootstrap-rtl', get_template_directory_uri() . '/css/bootstrap-rtl.css', false);
wp_enqueue_style('style', get_template_directory_uri().'/style.css', false);
wp_enqueue_style('header', get_template_directory_uri().'/css/header.css', false);
wp_enqueue_style('footer', get_template_directory_uri().'/css/footer.css', false);
}
add_action('wp_enqueue_scripts','cssjsloading');
instead of the following code in my <head></head> tag file, but it is not working!
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/bootstrap-rtl.css" />
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/style.css" />
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/header.css" />
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/header.css" />
I would be most grateful if you could help me

I think you should remove your false from wp_enqueue_style parameters if you do not need versioning.
Try simple wp_enqueue_style('style', get_template_directory_uri().'/style.css''); and check if this is working.

Related

Change default style based on title

I am trying to change the default style based on title of the page.I found that as the easiest way to accomplish needs.
I load the default styling option in header.php file:
<link rel="stylesheet" data-them="" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="all" />
I suppose <?php bloginfo('stylesheet_url'); ?> loads style.css which is on same path as header.php
I commented out this the line <link rel="stylesheet" data-them="" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="all" /> and tried to check title with php, based on that condition I wanted to load different style.css file.
<?php
$title = get_the_title();
if($title === "Title1"){
?><link rel="stylesheet" data-them="" href="style.css" type="text/css" media="all" /><?php
}
elseif($title === "Title2"){
?><link rel="stylesheet" data-them="" href="style2.css" type="text/css" media="all" /><?php
}
else{
?><link rel="stylesheet" data-them="" href="style3.css" type="text/css" media="all" /><?php
}
?>
This code does not work for me and not sure why.. Styling is messed up
Please find below style in your theme. Mostly enqueue in functions.php file.
EX:
wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(),
wp_get_theme()->get( 'Version' ) );
Please add below line after your theme's default style.
(get_stylesheet_uri())
wp_dequeue_style('twentynineteen-style');
After that check it your issue.
Please dequeue default style using below function.
wp_dequeue_style('default-style');

css is not loading in codeigniter 3.1

I am using codeigniter 3.1.
I am trying to read base_url from config file .
However hardcode value is working fine for the same .
my code to read base_url is :
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/bootstrap.min.css'); ?>' />
<script src='<?php echo base_url('assets/js/bootstrap.min.js'); ?>' />
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assests/css/styles.css'); ?>' />
My config is as follow :
$config['base_url'] = "http://localhost:63342/CI/";
In order to use base_url() you have to load url helper first.Load it in application/config/autoload.php like this..
$autoload['helper'] = array('url');
Make sure that your files must be in root under assets folder.
Try changing
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assests/css/styles.css'); ?>' />
To
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/styles.css'); ?>' />
Make sure assets in root directory out side of application folder
As you have missed spelt it.
try this
set folder location this way under CI Folder
CI
application
system
assets
then css link will be
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/bootstrap.min.css'); ?>' />
<script src='<?php echo base_url('assets/js/bootstrap.min.js'); ?>' />
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/styles.css'); ?>' />
make sure to load url helper
$autoload['helper'] = array('url');

why does my css nor html load in codeigniter?

When I include the following code within my view file:
<link rel="stylesheet" href="<?php echo base_url();>css/libs/animate.min.css" type="text/css" media="all">
<!-- Font Awesome icon library -->
<link href="<?php echo base_url();?>css/libs/font-awesome.min.css" rel="stylesheet" type="text/css" media="all">
<!-- Load primary stylesheet -->
<link rel="<?php echo base_url();?>stylesheet" href="css/skin.css" type="text/css" media="all">
Nothing loads not even HTML content,
but when I remove these lines HTML content loads properly.
So how do I load my CSS files? They are in my assests/css
You have to load helper in config/autoload.php
$autoload['helper'] = array('url', 'file','form');
in config.php]
$autoload['helper'] = array('url');
and base_url() should
$config['base_url'] = '';
you did mistaken to close the php script in first css linking
you wrote .
<?php echo base_url();>
instead of
<?php echo base_url();?>
and also check that you have loaded url helper in your code or not ?
use this
<link rel="stylesheet" href="<?php echo base_url();?>css/libs/animate.min.css" type="text/css" media="all">//mistake in this line missing '?'
<!-- Font Awesome icon library -->
<link href="<?php echo base_url();?>css/libs/font-awesome.min.css" rel="stylesheet" type="text/css" media="all">
<!-- Load primary stylesheet -->
<link rel="<?php echo base_url();?>stylesheet" href="css/skin.css" type="text/css" media="all">

Wordpress Theme issues

So i currently developing some Wordpress Theme nothing special. I ran into a problem another day. The problem goes like this, when I add the following code to the header.php
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/reset.css" type="text/css">
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css">
everything works fine, but when i make the following chages
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/css/reset.css" type="text/css">
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/css/style.css" type="text/css">
i get an error that the template missing.
The correct way to include stylesheet files is with the enqueue_style function.
go to your theme's functions.php file and search for: function themename_enqueue_style()
function themename_enqueue_style() {
/* Past the wp_enqueue_style() below in this function */
wp_enqueue_style( 'reset-style', get_template_directory_uri() . '/css/reset.css', false);
}
/* Don't forget Add_action below the function */
add_action( 'wp_enqueue_scripts', 'themename_scripts_styles' );
In a standard WordPress installation, the two statements would refer to different locations.
<?php bloginfo('stylesheet_url'); ?>
would return "yoursite.com/wp-content/themes/active_theme/style.css".
<?php bloginfo('stylesheet_directory'); ?>/css/style.css
would be "yoursite.com/wp-content/themes/active_theme/css/style.css".
you can also try this:
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/reset.css" type="text/css">
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/style.css" type="text/css">

CSS doesn't work when I add slash (/) at the end of my url

I'm new to code igniter and I wonder why my css doesn't work when I add slash ( / ) at the end of the url ..
Can someone help me why it doesn't work ? And help me make it work ?
Try this add code to your html head:
<link rel="stylesheet" href="<?php echo site_url('css/style.css');?>" type="text/css"/>
or
<link rel="stylesheet" href="<?php echo base_url();?>css/style.css" type="text/css"/>
CodeIgniter has method: site_url() - which generates your home url with '/' (slash) at the end.
To access public assets of your application
use this:
<link type="text/css" rel="stylesheet" href="<?php echo site_url(); ?>public/css/smoothness/jquery-ui-1.10.2.custom.min.css">
<script type="text/javascript" src="<?php echo site_url(); ?>public/js/custom.modernizr.js"></script>
Note: href="<?php echo site_url(); ?>public/css/smoothness/jquery-ui-1.10.2.custom.min.css"

Categories