Include root files into header files

I want to include files from the root directory of my site within the WordPress "header" file.

Is there any function for including a file from the root folder?

Topic wp-blog-header.php themes Wordpress

Category Web


If you want to "include" some CSS or Javascript (i.e. if you're not talking about PHP include), use the function get_site_url().

Example usage:

<script type="text/javascript" src="<?php echo get_site_url(); ?>/example_javascript.js"></script>

Its as simple as this.

include($_SERVER['DOCUMENT_ROOT']."/yourfile.php");

Cheers!!


If you are talking about the WordPress root, use:

include ABSPATH . "/extra-file.php";

ABSPATH is always the WordPress root, you can see that in your wp-config.php.


In your wp-config.php file, add the following line before /* That's all, stop editing! Happy blogging. */:

define( 'ROOT_FOLDER', dirname( __FILE__ ) );

Now you can use the following for including files from your root folder:

include ROOT_FOLDER . '/filename.php';

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.