0

I want some sort of variable to do what bloginfo( 'stylesheet_url' ) does.

Except in a different location!

Is there any way to set global directory locations?

Or am I stuck with copying the old chestnut: bloginfo( 'stylesheet_url' )/assets/styles

over and over again?

1 Answer 1

1

Sure you can do that. Create a simple plugin that looks something like this:

<?php
/*
Plugin Name: SiteWide Assets Location
Plugin URI: www.mysite.com
Description: Global URI for commonly used CSS and JS files
Version: 1.0
Author: Me
License: None
*/
define( 'SYSTEM_ASSETS', $_SERVER['DOCUMENT_ROOT'] . '/somedirectory/' );

Then, store your .css and .js files there (or in a subdirectory within that directory), and now in your themes you can simply refer to the constant SYSTEM_ASSETS whenever you want that URI location.

2
  • Cool! Thanks for the response! Is the constant considered a global variable? And is that even a big deal in this situation? Is there any built in way? Like set_blog_info()? Commented Oct 30, 2016 at 18:18
  • It's a constant...sort of a global variable. You could also create a simple function that returns the same exact string if you don't like constants. Either way, and neither one is a big deal...this type of thing is done all the time. Just pick unique names for your constants or functions declared outside a PHP class name scope.
    – C C
    Commented Oct 30, 2016 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.