• Hi WP members, Im trying to organize my theme directory with:

    mytheme/assets/css
    mytheme/assets/img
    mythem/assets/js

    My first attempt to do so (just using the css for this example) was by trying to re-define stylesheet_url but for the life of me could not find where this is defined. Ive checked out the codex page re: bloginfo at https://codex.www.ads-software.com/Function_Reference/bloginfo but dont see any data on editing values or creating custom bloginfo variables.

    My attempted work around was to just create my own custom vars in fucntions.php like so:

    /* Custom vars for assets/styles directory */
    $assets_css_dir = get_bloginfo('template_directory');
    $assets_css = $assets_css_dir . "/assets/css";
    $assets_img_dir = get_bloginfo('template_directory');
    $assets_img = $assets_img_dir . "/assets/images";
    $assets_js_dir = get_bloginfo('template_directory');
    $assets_js = $assets_js_dir . "/assets/js";

    Weird thing is when I echo $assets_css in my index.php it outputs correctly but when trying to use it in my header.php file (in the link tag) there is no output.

    Im a total newbie to WP so Im sure Im missing something and I would think this is a common issue for theme developers but as much as Ive searched I just cant seem to find a solution to this.

    Just FYI, I am using the twentyten theme if that means anything.

    Id like to know what the best approach is that is the most, hmm how would you say, WordPress’ish so as to stay within WP’s code structure.

    Any help or even just direction to some data would be much appreciated.

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You will need a style.css file in the theme’s root folder – otherwise WP will class the theme as broken. But, as long as you add the usual theme comment block, you could then import the actual stylesheets from assets/css into style.css using @import.

    For the js, you could just use:

    <script src="<?php bloginfo('template_directory'); ?>/assets/js/foo.js" type="text/javascript"></script>

    in header.php

    Thread Starter justclint

    (@justclint)

    Thanks for the response esmi!

    So I guess just to clarify, WP absolutely needs to have a style.css file in the themes root directory? I was trying to avoid this but if thats just how it works then I guess I will use the @import method.
    Now is this a WP thing or is it a twentyten theme thing?

    As for additional linked files (images, js) Im trying to avoid typing /assets/js……

    Is there no way to create a bloginfo(‘somevar’) and define it so that it goes directly to the assets/js folder so I could write:

    <?php bloginfo('js_dir'); ?>/file.js

    or for images

    <?php bloginfo('img_dir'); ?>/file.png

    From a functionality aspect is really no big deal but just thought it’d be nice to clean things up a bit.

    WP absolutely needs to have a style.css file in the themes root directory?

    Yep. And it’s a generic WordPress thing.

    Is there no way to create a bloginfo(‘somevar’) and define it so that it goes directly to the assets/js folder

    Not without some serious core hacking – which I definitely wouldn’t recommend.

    Thread Starter justclint

    (@justclint)

    Thanks esmi! That helps me a lot. Im glad I didnt continue trying to do this. I will follow your input as suggested.

    Thanks again!

    Any time. ??

    Thread Starter justclint

    (@justclint)

    Hey esmi, I forgot 1 thing from my original post. In regards to writing custom variables in functions.php I noticed I was able to add echo $myvar in the index.php and it worked as expected but when adding it to header.php it just simply did not output anything.

    Is there some unique behavior between different pages?

    Thanks!

    Because of the way in which the templating system works, it’s unwise to rely on a variable that is defined in a “global” file (such as functions.php) being available in all template files. The template system uses more than a straight-forward <?php include. Your best approach is to use your custom variables inside functions and then return or echo the result of the function.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘how to create or define bloginfo vars’ is closed to new replies.