How to Get a Directory Path with Wordpress and Include PHP File


Lot of time when I am building wordpress themes, I do include PHP files, Stylesheets, JS and many more, doing this is very simple as it requires just a simple code snippet which would be shown below:

To give you an idea of how the constant works, consider the case where you want to load a file containing some variable declarations for your theme. Create a new file in your theme's directory called config-variables.php, and add the following code to it:
// Comment
<?php
$blue = 1;
$red = 2;
$green = 3;
Next, open up your theme's header file—header.php—and add the following code at the very beginning of the file:
...
// Comment
<?php include (STYLESHEETPATH . '/config-variables.php '); ?>
Now, anywhere inside of your theme, you'll be able to access the variables defined within config-variables.php.
How to Get a Directory Path with Wordpress and Include PHP File How to Get a Directory Path with Wordpress and Include PHP File Reviewed by Sharemez on 04:03:00 Rating: 5

No comments:

Powered by Blogger.