Determine Path To Plugin and Content Directories

If you like to write a Plugin and you want to keep it downward compatible, then check beforehand the constants, because since WordPress version 2.6 you can rename the folder wp-content and this will also change the path to the Plugin folder.

Just a few lines of code are enough and you can work with the „new“ constants.

// Pre-2.6 compatibility
if ( !defined( 'WP_CONTENT_URL' ) )
	define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
if ( !defined( 'WP_CONTENT_DIR' ) )
	define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
if ( !defined( 'WP_PLUGIN_URL' ) )
	define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
if ( !defined( 'WP_PLUGIN_DIR' ) )
	define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
if ( !defined( 'WP_LANG_DIR') )
	define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );

I use this solution quite a long time. You can find the solution in the WordPress Codex now – „Determining Plugin and Content Directories“.


Posted

in

by

Comments

4 responses to “Determine Path To Plugin and Content Directories”

  1. […] Artikel WordPress Plugin- und Content-Verzeichnisse bestimmen bin ich schon auf die Möglichkeiten der Konstanten eingegangen, damit Erweiterungen in Themes […]

  2. […] already talked in my article Determine Path To Plugin and Content Directories about the possibilities how to keep functions in themes or plugins free from error if you rename a […]

  3. kamal Avatar

    Hi, and thanks for this information.
    as i’m a new wordpress and PHP user, wher can i insert this code? and is it possible to rename the folder “wp-content” to any name?
    Thanks

  4. Michael Avatar

    kamal, the code above is for theme-/ plugin authors. You can define the wp-content in your wp-config.php. Here is a good overview.