Kyle Hawk
Kyle Hawk

Reputation: 449

Include files outside WordPress directory

I have a directory /blog/ where I have WordPress installed. I'm creating a theme to handle the blog within that directory.

I have all my styles in /style/, includes in /includes/, and scripts in /scripts/. There has to be a way for me to include these files into my WordPress) theme. So basically, I want to include my stylesheet that the rest of the site (non-WordPress) is using. Yes, I'm aware WordPress requires a style.css in the theme root. However, I want to use this for other things as well. Such as including my header and footer, and also my compiled external JavaScript.

index.php
/style/
/blog/
    /wp-content/
        /themes/
            /my-theme/
/includes/
/scripts/

Summary: How do I access style / includes / scripts directories from within the WordPress theme?

Upvotes: 0

Views: 1691

Answers (3)

ow3n
ow3n

Reputation: 6597

You can do this inside any PHP file:

<?php include_once($_SERVER['DOCUMENT_ROOT'] .'/path/to/file.php'); ?>

Upvotes: 0

Ted
Ted

Reputation: 41

In your functions.php you can do the following:

function yourtheme_enqueue_scripts() {
  wp_enqueue_style( 'unique-id', $_SERVER['DOCUMENT_ROOT'] . '/styles/style.css', false );
  wp_enqueue_script( 'unique-id', $_SERVER['DOCUMENT_ROOT'] . '/scripts/filename.js', false );
}
add_action('wp_enqueue_scripts','yourtheme_enqueue_scripts');

Replace yourtheme, unique-id, style.css, filename.js with whatever is suitable for your situation.

Upvotes: 1

FKEinternet
FKEinternet

Reputation: 1060

The easiest way is to use a symlink inside the Wordpress directory that points to the file outside of it.

Upvotes: 0

Related Questions