Site icon WP Smith

Useful WordPress, Genesis, & Thesis Directory and URL (HTTP) PHP Constants

When creating WordPress plugins, themes, or tweaking plugins, themes, functions.php, you will often need to reference files and folders throughout the WordPress installation. Since WordPress 2.6 (if they are pre-2.6, then use die();), users have had the ability to move this directory anywhere they want, so you always want to avoid hardcoding so that the code is re-usable, especially with plugins. WordPress has defined a set of PHP CONSTANTS (by the way, constants are always UPPERCASE) to store the path to the wp-content and plugins directories. You can use these CONSTANTS in your plugins, child themes or functions.php for any paths you need regardless of where the actual directory might exist on the server.

You can set your own CONSTANT_DIR by (as a reminder, constants are always UPPERCASE):

[php]define('CONSTANT_DIR', ABSPATH . 'wp-content'); //sets DIR[/php]

You can set your own CONSTANT_URL by (as a reminder, constants are always UPPERCASE):

[php]define('CONSTANT_URL', get_option('siteurl').'/wp-content/'); //sets URL[/php]

For GENESIS Users, some CONSTANTS of interests are:

For THESIS (1.8) Users, some CONSTANTS of interests are:

Are there any CONSTANTS that are used quite often that I missed?