1

I am building a wordpress theme from scratch on a subdomain and I want to use the same CSS files across my entire site. My problem is linking my wordpress PHP files (which are on the subdomain) to my CSS files (which are on the main domain).

I have tried going into theme.php and changing the ['/style.css'] to an absolute reference such as 'http://diginomics.com/css/style.css' but it doesn't work.

function get_stylesheet_uri() {
    $stylesheet_dir_uri = get_stylesheet_directory_uri();
    $stylesheet_uri = $stylesheet_dir_uri . '/style.css';

I am assuming my subdomain doesn't have permissions to access my root folder or something is simply wrong with the syntax. I would like to link my wordpress theme to all my CSS files and frameworks and use theme site wide and on all my subdomains.

Also, what would the solution be to link my Javascript files site-wide as well?

2 Answers 2

0

If you're using an absolute reference like that, you'd want to include the full file path, like http://diginomics.com/wp-content/themes/THEMENAME/css/style.css

I believe any time you call the functions like get_stylesheet_directory() or get_stylesheet_directory_uri() it will return the path for the current theme.

Just keep in mind that all themes need a style.css file.

I would have posted this in a comment but I'm not allowed yet.

4
  • My style.css file is located at diginomics.com/css/style.css whereas my wordpress installation is at blog.diginomics.com. I am trying to use an absolute reference to the root domain style.css instead of the style.css in my WP theme directory. Aug 24, 2014 at 20:03
  • I believe every theme needs a style.css file to properly be accepted in a WP installation. Have you thought about creating a standard style.css file for your theme, then at the start of it use a css import for the other stylesheet?
    – Will S.
    Aug 24, 2014 at 20:08
  • Beautiful, I messed around with the import function and got it working properly with all 10 CSS frameworks. Thank you Will. I was also wondering if I would need to import the Javascript files as well and how could I do this? Aug 24, 2014 at 21:46
  • wp_register_script() requires a source for the script and sets a handle. Then just run wp_enqueue_scripts() codex.wordpress.org/Function_Reference/wp_register_script
    – Will S.
    Aug 25, 2014 at 0:07
1

@import is not good solution AFAIK it takes a bit more time to download @import link and then process it, so you gonna have a little bit of network bottleneck. I'd go with default style.css file where you have all wordpress required meta data and then renamed diginomics.com/css/style.css to gobal.css and linked it with absolute link. Such semantic naming is a good practice and defo would help you in.

Your code would look something like that:

function MyAdditionalStyles() {

     wp_enqueue_style( 'your-speacial-style-name', 'http://diginomics.com/css/GLOBAL.css' );
     wp_enqueue_style( 'your-second-speacial-style-name', 'http://diginomics.com/css/ANOTHER-GLOBAL.css' );

     wp_enqueue_script( 'your-script-name', 'http://diginomics.com/js/GLOBAL.js' );
}

add_action( 'wp_enqueue_scripts', 'MyAdditionalStyles' );

Here is a good read :) http://codex.wordpress.org/Function_Reference/wp_enqueue_style

Good luck

Your Answer

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

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