Support » Themes and Templates » Writing a relative path to a theme’s stylesheet

  • Resolved tactics

    (@tactics)


    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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • use get_bloginfo(); instead.

    <?php get_bloginfo(‘template_url’); ?>

    Thread Starter tactics

    (@tactics)

    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
    ?>
    Thread Starter tactics

    (@tactics)

    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
    ?>

    Right on… I should have posted:

    $my_url = get_bloginfo('template_url') . '/css/default.css';
    $ss->addStyle("default", $my_url, "screen");
    Thread Starter tactics

    (@tactics)

    Sorry for the duplicate reply.

    That worked like a charm thanks a million!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Writing a relative path to a theme’s stylesheet’ is closed to new replies.