WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Mar 22 2011

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.

  • 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?

Written by Travis Smith · Categorized: Genesis

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Comments

  1. hamza khan says

    March 17, 2012 at 10:09 am

    thanks useful

    Reply
  2. Dave says

    May 21, 2012 at 1:50 pm

    Travis,
    That’s a very nice list, thanks so much!

    I’m wondering if there’s one for the site root of a Genesis install? Or plain WordPress install, for that matter? Like most, I find myself frequently working on temp URL’s on some server, and it would be nice to avoid changing the funny file path that this makes for some items.

    I just ran into the handy idea of setting the site root in wp-config so that you could use plain old “/” as your root for this kind of stuff.

    Your thoughts?
    Thanks, Dave

    Reply
    • Travis Smith says

      July 25, 2012 at 1:05 am

      I am not sure I follow you. When dealing with images, etc., I create and use a shortcode like [ wpurl] that you can find in my Genesis Shortcodes plugin.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in