wordpress stylesheet linking

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

wordpress stylesheet linking

Post by gautamz07 »

I was just going through this tutorial https://www.youtube.com/watch?v=k7olvEe ... aqOVpX7qi5 and basically the author recommends that the css stylesheet be imported like so:

Code: Select all

<?php
    function learningWordPress_resources() {
        wp_enqueue_style('style' , get_stylesheet_uri());
    }
    add_action('wp_enqueue_scripts' , 'learningWordPress_resources');
?>
My header.php of my theme looks like so:

Code: Select all

<!doctype html>
<html <?php  language_attributes(); ?> >
    <head>
        <meta charset="<?php  bloginfo('charset');   ?>">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title><?php bloginfo('name');  ?></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">        

        <?php  wp_head(); ?>

    </head>
    <body <?php  body_class(); ?>>



    <header class="site-header">
        <h1><a href="<?php echo home_url(); ?>"></a><?php bloginfo('name');  ?></h1>
        <h5><?php bloginfo('description'); ?></h5>
    </header>
But i am still not seeing the effect of my stylesheet , can anybody point me to what exactly am i doing wrong ?

Thank you.
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: wordpress stylesheet linking

Post by gautamz07 »

EDIT:: On further inspection i found out that if i post the contents of header.php in index.php the stylesheet is loading fine , which means that my functions.php files is working fine. So i guess the problem is with my header.php file, I have updated above what my header.php file looks like, so can somebody tell me whats wrong with my header.php file now ?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: wordpress stylesheet linking

Post by Celauran »

gautamz07 wrote:On further inspection i found out that if i post the contents of header.php in index.php the stylesheet is loading fine
This suggests that your header.php file is also fine, but possibly not being loaded, so the problem may lie in your index.php
cybershot
Forum Commoner
Posts: 29
Joined: Thu Jul 24, 2008 12:06 pm

Re: wordpress stylesheet linking

Post by cybershot »

does your index.php file have something like this

Code: Select all

get_header();
if not, it needs it. Place that line of text at the very top of your index.php file before anything else and that should solve it. Also make sure that your index file has one for the footer

Code: Select all

get_footer();
placed at the very end of the index.php file
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: wordpress stylesheet linking

Post by gautamz07 »

@celauran and @cybershot , you guys were right , i found out that i was missing the following:

get_header();
tamziedahmed
Forum Newbie
Posts: 1
Joined: Fri Apr 15, 2016 10:03 am

Re: wordpress stylesheet linking

Post by tamziedahmed »

Use <link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" media="screen" /> and then @import the additional stylesheets at the top of style.css after the theme data block.
Last edited by Celauran on Fri Apr 15, 2016 10:11 am, edited 1 time in total.
Reason: Removed link spam. Don't do that again.
Post Reply