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.
- WP_CONTENT_URL: Full URL to wp-content
- WP_CONTENT_DIR: The server path to the wp-content directory
- WP_PLUGIN_URL: Full URL to the plugins directory
- WP_PLUGIN_DIR: The server path to the plugins directory
- WP_LANG_DIR: The server path to the language directory
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:
- STYLESHEETPATH: /.../.../.../..../.../.../wp-content/themes/child_theme
- TEMPLATEPATH: /.../.../.../..../.../.../wp-content/themes/genesis
- PARENT_URL: get_bloginfo(‘template_directory’): e.g., http://domain.com/wp-content/themes/genesis
- CHILD_URL: get_bloginfo(‘stylesheet_directory’): e.g., http://domain.com/wp-content/themes/child_theme
- PARENT_THEME_VERSION: refers to the Genesis version running
- PARENT_THEME_NAME = 'Genesis'
- GENESIS_LANGUAGES_URL (sets to Genesis Library for Child Themes)
For THESIS (1.8) Users, some CONSTANTS of interests are:
- THESIS_CUSTOM = STYLESHEETPATH: /.../.../.../..../.../.../wp-content/themes/thesis_18/custom
- THESIS_CUSTOM_FOLDER: get_bloginfo('stylesheet_directory') . '/custom': e.g., http://domain.com/wp-content/themes/thesis_18/custom
- THESIS_LAYOUT_CSS: THESIS_CUSTOM . '/layout.css: e.g., http://domain.com/wp-content/themes/thesis_18/layout.css
- THESIS_ROTATOR:THESIS_CUSTOM . '/rotator': e.g., http://domain.com/wp-content/themes/thesis_18/rotator
- THESIS_ROTATOR_FOLDER: THESIS_CUSTOM_FOLDER . '/rotator': e.g., http://domain.com/wp-content/themes/thesis_18/rotator
Are there any CONSTANTS that are used quite often that I missed?