SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't link to css on local host

    I have wordpress running on WAMP and I am able to pull up the page with the custom template, but for some reason the css won't load. When I veiw the page source I get an error message that says,

    "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>404 Not Found</title>
    </head><body>
    <h1>Not Found</h1>
    <p>The requested URL /wordpress/css/style.css was not found on this server.</p>
    </body></html>"

    I don't know how the path isn't correct since I created the path using the "Attach Style Sheet" link button in Dreamweaver.

    What could be wrong?

  2. #2
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just got it to work doing this

    <link href="http://localhost/wordpress/wp-content/themes/BLANK-Theme/css/style.css" rel="stylesheet" type="text/css">

    However, I don't get why the first link doesn't work?

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by BrianBam View Post
    I don't get why the first link doesn't work?
    What was it?

  4. #4
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, sorry i guess I did forget the original.

    <link href="css/style.css" rel="stylesheet" type="text/css">

  5. #5
    SitePoint Addict
    Join Date
    Oct 2008
    Location
    Virtual World is my location
    Posts
    316
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    To refer a css with relative path you need to add stylesheet directory or theme directory link before the css

    You can read details here : http://codex.wordpress.org/Function_Reference/bloginfo
    FreelanceNext.com - Freelance Projects / Jobs & more...
    BargainNext.com - coupons / deals / bargains / offers & more...

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    This—

    Code:
    <link href="http://localhost/wordpress/wp-content/themes/BLANK-Theme/css/style.css" rel="stylesheet" type="text/css">
    works because it's always pointing to the same place, while this—

    Code:
    <link href="css/style.css" rel="stylesheet" type="text/css">
    most likely is never pointing to the right place, because it would have to be on a page inside the same folder as the /css/ folder. If you don't want the the full URL, you could try this:

    Code:
    <link href="/wordpress/wp-content/themes/BLANK-Theme/css/style.css" rel="stylesheet" type="text/css">

  7. #7
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I knew that it was pointing to an absolute place with "http//:...." but I didn't know that you have to use stylesheet directory or theme directory to refer to css using a relative path. thx

  8. #8
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaagare View Post
    To refer a css with relative path you need to add stylesheet directory or theme directory link before the css

    You can read details here : http://codex.wordpress.org/Function_Reference/bloginfo
    So, I looked at the linked which you provided me with and I got this to work PARTIALLY

    <link href="<?php echo get_stylesheet_uri(); ?>" rel="stylesheet" type="text/css"> which output this link

    "http://localhost/wordpress/wp-content/themes/Connect4/style.css"

    The problem is that I had to take my style sheet out of the css folder.

    However, what I would like is this link output

    "http://localhost/wordpress/wp-content/themes/Connect4/css/style.css"

  9. #9
    SitePoint Addict deadmix's Avatar
    Join Date
    Jun 2009
    Location
    france
    Posts
    210
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    hello there,

    so in this Case use :

    <link href="<?php echo get_template_directory_uri(); ?>/css/style.css" rel="stylesheet" type="text/css">

    Goodluck

  10. #10
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I actually tried this earlier

    <link href="<?php echo get_stylesheet_uri(); ?>/css/style.css" rel="stylesheet" type="text/css"> which led to the output of this

    <link href="http://localhost/wordpress/wp-content/themes/Connect4/style.css/css/style.css" rel="stylesheet" type="text/css">

    which obviously is wrong.

  11. #11
    SitePoint Addict deadmix's Avatar
    Join Date
    Jun 2009
    Location
    france
    Posts
    210
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    ok, so try this now :

    <link href="<?php wp_enqueue_style( ); ?>/css/style.css" rel="stylesheet" type="text/css">

    Open Function.php of your theme and add this :

    Code:
    function my_styles_method() {  
        // Register the style like this for a theme:  
        wp_register_style( 'my-custom-style', get_template_directory_uri().'/css/style.css');  
    
        // enqueue the stule  
        wp_enqueue_style( 'my-custom-style' );  
    }  
    add_action( 'wp_enqueue_scripts', 'my_styles_method' );
    To learn more about wp_enqueue_style : Link

  12. #12
    SitePoint Addict
    Join Date
    Oct 2008
    Location
    Virtual World is my location
    Posts
    316
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BrianBam View Post
    Thanks. I actually tried this earlier

    <link href="<?php echo get_stylesheet_uri(); ?>/css/style.css" rel="stylesheet" type="text/css"> which led to the output of this

    <link href="http://localhost/wordpress/wp-content/themes/Connect4/style.css/css/style.css" rel="stylesheet" type="text/css">

    which obviously is wrong.

    Try this and it should work

    Code:
    <?php echo get_bloginfo ( 'stylesheet_directory' ); ?>
    So now your code would be
    Code:
    <link href="<?php echo get_bloginfo ( 'stylesheet_directory' ); ?>/css/style.css" rel="stylesheet" type="text/css">
    FreelanceNext.com - Freelance Projects / Jobs & more...
    BargainNext.com - coupons / deals / bargains / offers & more...

  13. #13
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, sorry deadmix's initial response solved my problem. I was just saying that my first method didn't solve the problem.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •