I'm using the polylang plugin. Additional css is required for the arabic language. How can I run css according to the subfolder in the functions?
example:
//This is your own css file
<link rel="stylesheet" href="/yellow.css" type="text/css" media="screen,projection" />
//this is the code that will also work according to subfolders
<?php if( url(www.example.com/ar) ) ?>
<link rel="stylesheet" href="/blue.css" type="text/css" media="screen" />
<?php endif;?>
If your trying to fetch styles for a page in php.
Try this
<!--Styles included -->
<style>
<?php include '/blue.css'?>
</style>
wp_enqueue_style('theme', PLUGIN_URL . '/assets/css/test.css');
Another
function load_admin_script() {
wp_enqueue_style('theme', DSSLIDER_PATH . 'assets/css/test.css');
}
add_action( 'admin_enqueue_scripts', 'load_admin_script' );
Related
I need to force CSS changes to go live immediately and I found that add a version to CSS would help to do that as bellow.
<link rel="stylesheet" href="css/style.css?version=123456" media="all"/>
I need to automate this as it is difficult to change the main file always when need to do small change to css file.
So I found following line of code(sample) in PHP doing the same job.
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" type="text/css" media="screen, projection" />
I have tried to convert this line to Smarty, but it is giving error.
code :
<link rel="stylesheet" href="css/style.css?version={#filemtime:css/style.css} />
error:
syntax error: unrecognized tag: #filemtime:...........
Anybody has an idea how to do this ?
Thanks in advance
You can add this modifier to smarty plugin folder,
function smarty_modifier_filemtime($path){
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
return filemtime( YOUR_HOME_DIR.$path );
}
then call it like bellow,
<link rel="stylesheet" href="/css/style.css?v={'/css/style.css'|#filemtime}" type="text/css">
I have written all my CSS styles into a .css file; now I want to include that CSS file into a PHP file. I have tried this:
<link href="login.css" rel="stylesheet" type="text/css"></link>
but it is not working.
Here is how to include external javascript and css files in your php code
<?php
//include CSS Style Sheet
echo "<link rel='stylesheet' type='text/css' href='path-to-css-file' />";
//include a javascript file
echo "<script type='text/javascript' src='path-to-javascript-file'></script>";
?>
If you want to include the javascript and css source code inside the php file itself then you can do it like this
<?php
//include CSS Style Sheet
echo "<style type='text/css'>
table{
border: 1px solid;
color: blue;
}
/*heading class*/
.heading1 {
font size: 10px;
}
</style>";
//include a javascript file
echo "<script type='text/javascript'>
/* All your javascript code goes here*/
</script>";
?>
Don't use a closing tag for link elements, e.g.:
<link href="login.css" rel="stylesheet" type="text/css"></link>
It should use a self closing tag, like so:
<link href="login.css" rel="stylesheet" type="text/css" />
Remove the closing </link>, as this is not required.
Also, make sure that your page and login.css are in the same directory, or in other words, the path for CSS file should be correct.
To include it into PHP page, you'll need to print this to browser using echo:
echo '<link href="login.css" rel="stylesheet" type="text/css" />';
I need to change the css of the home page only, I have googled and a lot of the suggestions were to add the page id as part of the css selector. But when I try it, it doesn't seem to work? I want to change the class ".contentclass" and the pages id is "599" so here's what I've tried:
.post-id-599 .contentclass {}
.page-id-599 .contentclass {}
.body-id-599 .contentclass {}
none of them seems to be working...
Link to the webpage I'm working on: Link
Try using the right click "inspect element" or equivalent for your browser.
When I look at your site I see something like this
<body class="page page-id-624 woocommerce-cart woocommerce-page boxed varukorg" style="">
So for example for this page:
http://witdesign.se/wp/varukorg
you would use
body.post-id-624 .contentclass {}
Any styles within the braces will be applicable to the pages with a body class of post-id-668
To be sure, you will need to check what renders in your browser using an inspector.
If your theme uses body_class() in the body tag, you will have a specific css class for the front page (.home), which you could use in the stylesheet;
Example (might be different for your theme):
.home #content .entry { color: #123edf; }
to overwerite the genral stylesheet style.css, you could use a conditional statement in header.php to link a specific stylesheet for the front page:
Example:
<?php if( is_home() ) { ?>
<link rel="stylesheet" type="text/css" media="all" href="<?php echo get_stylesheet_directory_uri(); ?>/front-style.css" />
<?php } ?>
the code needs to be after the link to the general stylesheet.
(instead of is_home() you might need to use is_front_page() )
Check: Conditional_Tags and get_stylesheet_directory_uri
--
alternative, to load a different stylesheet instead of the general stylesheet, use the conditional statement with an else:
(this code would replace the link of the general stylesheet)
Example:
<?php if( is_home() ) { ?>
<link rel="stylesheet" type="text/css" media="all" href="<?php echo get_stylesheet_directory_uri(); ?>/front-style.css" />
<?php } else { ?>
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
<?php } ?>
I am new to wordpress.. I have installed my theme named 'hare'. Now I want to add some javascripts files as well as css files into the index.php page. But I am not finding the desired output.
following is the code i have written..
<?php get_header(); ?>
// Some content
<?php get_footer(); ?>
<!-- JQuery libs
================================================== -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!-- js jQuery wait for images Plugin ====================== -->
<script src="<?php bloginfo(template_directory ); ?>/javascripts/jquery.waitforimages.js"></script>
<!-- js jQuery flexslider Plugin ====================== -->
<script src="<?php bloginfo(template_url); ?>/javascripts/jquery.flexslider-min.js"></script>
<!-- jQuery Cycle Plugin ====================================== -->
<script src="<?php bloginfo(template_url); ?>/javascripts/jquery.cycle.all.js"></script>
<!-- jQuery Cycle Plugin ====================================== -->
<script src="<?php bloginfo(template_url); ?>/javascripts/jquery.fullscreen-min.js"></script>
<!-- js jQuery jcarousellite Plugin ====================== -->
<script src="<?php bloginfo(template_url); ?>/javascripts/jcarousellite_1.0.1.min.js"></script>
<!-- js Fancybox Plugin ================================= -->
<link rel="stylesheet" href="<?php bloginfo(template_directory); ?>/javascripts/fancyBox-2/jquery.fancybox.css">
<script src="<?php bloginfo(template_url); ?>/javascripts/fancyBox-2/jquery.fancybox.pack.js"></script>
<!--fancybox helpers-->
<link rel="stylesheet" href="<?php bloginfo(template_directory); ?>/javascripts/fancyBox-2/helpers/jquery.fancybox-buttons.css"/>
<script src="<?php bloginfo(template_url); ?>/javascripts/fancyBox-2/helpers/jquery.fancybox-buttons.js"></script>
<!-- js jQuery qtip plugin ====================== -->
<script src="<?php bloginfo(template_url); ?>/javascripts/jquery.qtip-1.0.0-rc3.min.js"></script>
<!-- toTop ====================== -->
<script src="<?php bloginfo(template_url); ?>/javascripts/goToTop.js"></script>
<!-- js jQuery my own functions ====================== -->
<script src="<?php bloginfo(template_url); ?>/javascripts/functions.js"></script>
<!-- <script src="javascripts/jquery.tweet.js"></script> -->
<!-- JS twitter scripts ================================== -->
<script src="http://twitter.com/javascripts/blogger.js"></script>
<script src="http://twitter.com/statuses/user_timeline/EnvatoWebDesign.json?callback=twitterCallback2&count=5"></script>
<!-- End Document
================================================== -->
</body>
</html>
Is my this way is correct??
If not then please correct me..
Thank you in advance
In your comments you may be referring to these guidelines from yahoo. There are, however a few caveats to this rule. Most importantly, Google Analytics prefers it's snippet be placed within the <head> section and won't allow you to use Analytics for Webmaster Tools authentication unless the snippet is in head.
More importantly, you don't want to include your JS and CSS files directly in your theme templates like this. It works, but it is very un-WordPress-y.
The "correct" way to include additional scripts and styles in a WordPress theme is to use the wp_enqueue_script() and wp_enqueue_style() functions within a hook in functions.php, like so:
function my_custom_styles_function() {
wp_enqueue_style( 'my-style', get_stylesheet_directory() . DS . 'javascript' . DS . 'my-plugin' . DS . 'my-plugin-style.css', array(), '1.0' );
...
}
add_action('wp_enqueue_scripts', 'my_custom_styles_function');
WordPress actually has jQuery included by default, although without the $ shortcut established. You can use WordPress's jQuery and start all of your custom scripts with jQuery(...); instead of $(...); but this can cause problems for some plugins. If you want to include your own version of jquery, you should first use wp_dequeue_style() to dequeue the "built-in" jQuery.
Finally, if you do want to include you scripts in the footer, the wp_enqueue_script() function has a flag, $in_footer to defer particular scripts to the footer.
The answer provide by #qccreative is the right one. You should include all the js/css files you need to your page using the functions.php file that you must have within your theme. if you dont have it just create one and make a function for import your files just like the answer above.
you can even manage in what page you want to load your scripts.
also this is the safest way WP provide for including scripts in an organized way.
this hook that wordpress provide WP_ENQUEQUE_SCRIPTS its a function that will add the scripts within your action to the site.
heres another example:
function load_javascript_files(){
wp_register_script( 'jquery-accordion', get_template_directory_uri() . '/js/jquery.accordion.js', array('jquery'),true );
wp_enqueue_script('jquery-accordion');
}
add_action('wp_enqueue_scripts', 'load_javascript_files');
Good luck buddy
From the code you have put you would create a header.php file in your themes folder and include the JS in there. An example would be like follows:
`<!DOCTYPE html>
<html>
<head>
<title><?php bloginfo( 'name' ); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="<?php bloginfo( 'template_url' ); ?>/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="<?php bloginfo( 'template_url' ); ?>/jQuery-validate.js" type="text/javascript"></script>
<link rel="stylesheet" href="<?php bloginfo( 'template_url' ); ?>/style.css" type="text/css" />
<?php wp_head(); ?>
</head>
<body>
/**
* Proper way to enqueue scripts and styles.
*/
function custom_links() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() );
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'custom_links' );
If you need to linked your CSS file than you can use wp_enqueue_style and if you need to linked JavaScript than you can use wp_enqueue_script.
wp_enqueue_scripts this is work on frontend side of wordpress.
admin_enqueue_scripts this is works on backend side of wordpress.
I hope it's help to all people.
I just installed Wordpress, and one thing I discovered is that site URL appears to be hardcoded in all the generated HTML.
For example, I see things like:
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="http://www.mywebserver.com/wp- content/themes/twentyeleven/style.css" />
<link rel="pingback" href="http://www.mywebserver.com/xmlrpc.php" />
Is there a way to tell Wordpress to strip out the domain name in the generated URLs? For example, I would prefer:
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="/wp-content/themes/twentyeleven/style.css" />
<link rel="pingback" href="/xmlrpc.php" />
A couple links of code can fix it, in your functions file and header file: Fix absolute links in Wordpress
Functions.php
function fix_links($input) {
return preg_replace('!http(s)?://' . $_SERVER['SERVER_NAME'] . '/!', '/', $input);
}
Header.php -- before you output any HTML
ob_start('fix_links');