WordPress.org

Ready to get started?Download WordPress

Forums

Can't load single stylesheet on a single page. (5 posts)

  1. nubdienub
    Member
    Posted 1 year ago #

    Hello, I have a little problem regarding a WordPress theme and a single css file that I want to use on one single page. I have googled it and I was provided with this code:

    <?php if ( is_page('testen') ) { ?>
         <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/style2.css" type="text/css" media="screen" />
    <?php } else { ?>
         <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    <?php } ?>

    This code says, if I am on the page "testen", I will call that single stylesheet on that page (style2.css), otherwise I will just call the regular stylesheet on any other page (style.css).

    Now, I have a seperate folder in my theme folder (custom theme) where I have my stylesheets. These stylesheets are all custom. The regular stylesheet just refers to all other stylesheets in my css folder. This is the code of style.css:

    @import "css/layout.css";
    @import "css/tijink.css";
    @import "css/style2.css";

    As you can see it uses 3 stylesheets, when I go to my homepage or any other page but "testen" the stylesheet loads. But when I go to "testen", the page is different (because the php code says if its different load style2.css) but it does not load the style2.css. It can't find the file for some reason. The "testen" page is just a "normal" HTML page with text and absolutely no markup. Can anyone help me out here to let my code find the style2.css?

    Thanks in advance.

  2. W.P. Ginfo
    Member
    Posted 1 year ago #

    I assume you've done a search using FTP and tried to find it.

    If you cannot find it, why not create it yourself and control things, just the way you like it?
    Test using an obvious setting to see if your site 'can find the newly created 'style2.css'. Then -when OK- do the 'proper job'.

  3. alchymyth
    Forum Moderator
    Posted 1 year ago #

    you need to enter the right path in here:

    <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/style2.css" type="text/css" media="screen" />

    as the style2.css seems to be in the sub-folder /css try this code:

    <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/css/style2.css" type="text/css" media="screen" />
  4. nubdienub
    Member
    Posted 1 year ago #

    @Ginfo, it was already created.

    @Alchymyth, that does not work but I have already fixed it myself

    Fix:

    I've created another stylesheet in the mainfolder just like style.css and imported the style2.css inside that sheet. For some reason it can find the sheet inside the same folder as the header.php but not inside a subfolder, so you have to do it this way.

  5. W.P. Ginfo
    Member
    Posted 1 year ago #

    Please don't forget to mark the thread as 'resolved' [in the right sidebar]

Topic Closed

This topic has been closed to new replies.

About this Topic