Forums

[resolved] Writing a relative path to a theme's stylesheet (6 posts)

  1. tactics
    Member
    Posted 10 months ago #

    Hi folks,

    I'm building a new theme I'm hoping to release for download soon. The theme contains a stylsheet switcher that allows the user to change the look of the site, without having to load a whole new theme. It works great, but I need to figure out how to modify one line of code so I don't have to specify the absolute path to the stylesheet (since it will be different for everyone). The line of code I have now is:

    $ss->addStyle("default", "http://www.mysite.com/blog/wp-content/themes/Access/css/default.css", "screen");

    I tried using:

    $ss->addStyle("default", "<?php bloginfo('template_url'); ?>/css/default.css", "screen");

    But <?php bloginfo('template_url'); ?> renders out as text. How can I alter that line so it will write out the path to the template?

  2. mfields
    Member
    Posted 10 months ago #

    use get_bloginfo(); instead.

    <?php get_bloginfo('template_url'); ?>

  3. tactics
    Member
    Posted 10 months ago #

    Thanks, but unfortunately, it's the same result. When it renders, I get:

    <link rel="stylesheet" href="<?php get_bloginfo('template_url'); ?>/css/default.css" media="Screen" type="text/css" />

    Perhaps it would help if I posted the whole block:

    <?php
    // BEGIN STYLESWITCHER CODE
    if(!isset($reqPath)){ $reqPath = ""; }
    require_once($reqPath ."inc/styleswitcher.php");
    $ss = new Styleswitcher();
    $ss->addStyle("default", "http://www.mysite.com/blog/wp-content/themes/Access/css/default.css", "Screen");
    $ss->addStyle("hc", "http://www.mysite.com/blog/wp-content/themes/Access/css/hc.css", "Screen");
    $ss->createSet("style");
    $ss->addStyleToSet("style", "default", true);
    $ss->addStyleToSet("style", "hc");
    $ss->cookieDomain = ".". $_SERVER['HTTP_HOST'];
    $ss->cookieName = "cwStyle";
    $ss->printStyles();
    // End Styleswitcher code
    ?>
  4. tactics
    Member
    Posted 10 months ago #

    Thanks, but unfortunately, it's the same result. When it renders, I get:

    <link rel="stylesheet" href="<?php get_bloginfo('template_url'); ?>/css/default.css" media="Screen" type="text/css" />

    Perhaps it would help if I posted the whole block:

    <?php
    // BEGIN STYLESWITCHER CODE
    if(!isset($reqPath)){ $reqPath = ""; }
    require_once($reqPath ."inc/styleswitcher.php");
    $ss = new Styleswitcher();
    $ss->addStyle("default", "http://www.mysite.com/blog/wp-content/themes/Access/css/default.css", "Screen");
    $ss->addStyle("hc", "http://www.mysite.com/blog/wp-content/themes/Access/css/hc.css", "Screen");
    $ss->createSet("style");
    $ss->addStyleToSet("style", "default", true);
    $ss->addStyleToSet("style", "hc");
    $ss->cookieDomain = ".". $_SERVER['HTTP_HOST'];
    $ss->cookieName = "cwStyle";
    $ss->printStyles();
    // End Styleswitcher code
    ?>
  5. mfields
    Member
    Posted 10 months ago #

    Right on... I should have posted:

    $my_url = get_bloginfo('template_url') . '/css/default.css';
    $ss->addStyle("default", $my_url, "screen");
  6. tactics
    Member
    Posted 10 months ago #

    Sorry for the duplicate reply.

    That worked like a charm thanks a million!

Reply

You must log in to post.

About this Topic

Tags

No tags yet.