WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Need help with Stylesheet Url in WP! (9 posts)

  1. pookey
    Member
    Posted 6 years ago #

    Hi!

    I have created a random background php script in my theme which is working. I want to do the same with my css. The only problem is how do I link it to my header?
    With the random background script, I added <?php include("background.php");
    ?>
    before anything else in my header.php. I also added <body background="<?=$_SESSION['background']?>"> after </head>.

    But with my CSS?

    I know I have to include this <?php include("css.php");
    ?>

    But what about my $_SESSION['css']?

    It should be added here somewhere? and how? href="<?php bloginfo('stylesheet_url'); ?>"

    Thanks!

  2. Khairil Zhafri
    Member
    Posted 6 years ago #

    Confused.

    What's in background.php? css.php?

    Mate, am really confused the way you telling the story.

  3. pookey
    Member
    Posted 6 years ago #

    Oh sorry..

    The bakcground.php is creating a random background image per session..

    background.php:

    <?php
    session_start();
    
    if(!$_SESSION['background'])
    $_SESSION['background'] = 'url/portfolio/wp-content/themes/portfolio/background/background' . mt_rand(1, 5). '.jpg';
    
    ?>

    I thought I could do the same with my css..

    css.php:

    <?php
    session_start();
    
    if(!$_SESSION['css'])
    $_SESSION['css'] = 'url/portfolio/wp-content/themes/portfolio/css' . mt_rand(1, 3). '.css';
    
    ?>

    So as I said, for the random background script, I added

    <?php include("background.php");
     ?>

    before anything else in my header.php.

    I also added

    <body background="<?=$_SESSION['background']?>">

    after </head>.

    But I don't know how to include the css.php in my header..

  4. Khairil Zhafri
    Member
    Posted 6 years ago #

    Then,

    1. Add <?php include("css.php"); ?> somewhere around <?php include("background.php"); ?>
    2. Add <link rel="stylesheet" href="<?=$_SESSION['css']?>" type="text/css" media="screen" /> anywhere between <?php include("css.php"); ?> and </head>

  5. pookey
    Member
    Posted 6 years ago #

    Thank you!, but it does not work.. I think it's because I still have <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> in my header.php..

    And if I remove it, the page will be shown without css! I also heard that wordpress needs the style.css file in the theme folder?

  6. moshu
    Member
    Posted 6 years ago #

    Basically, it does. Otherwise it will report it as incomplete theme. The minimum that a theme needs = index.php + style.css.

  7. pookey
    Member
    Posted 6 years ago #

    So it won't work, and I have to put the css files in an array instead and have them in the main folder?

    Or can I put some kind of link to the php code/file inside style.css?

    Or is it any other ways I can use? Does anyone know?

    Thanks for the answers poppacket and moshu..

  8. Khairil Zhafri
    Member
    Posted 6 years ago #

    Try to change the position of <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />.

    If its position is before the <link> for the random stylesheet, make it after then and vice versa.

    And make sure you have the files css1.css, css2.css and css3.css inside the theme directory.

  9. pookey
    Member
    Posted 6 years ago #

    I just removed <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" / and it works!

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic