WordPress overview

WordPress has a lot of directories which you might need. And a lot of functions to get those directories. I myself often doubt which function returns what. Ans if it has a trailing slash or not. so here is an overview. I’ve also put all these functions in this small plugin: URL-overview plugin

I’m assuming a few things:

  • The website is: https://janw.me/
  • WordPress is in a subdirectory: https://janw.me/wp/
  • The website root on the server is: /var/www/janw.me/www/
  • So wordpress is in: /var/www/janw.me/www/wp/
  • The theme is called ‘child-theme’ and it’s parent is ‘parent-theme’

The Url’s that bloginfo() usses:

bloginfo('url')                  // https://janw.me  use home_url('/')
bloginfo('wpurl')                // https://janw.me/wp use site_url('/')
bloginfo('stylesheet_directory') // https://janw.me/wp/wp-content/themes/child-theme
bloginfo('stylesheet_url')       // https://janw.me/wp/wp-content/themes/child-theme/style.css
bloginfo('template_directory')   // https://janw.me/wp/wp-content/themes/parent-theme
bloginfo('template_url')         // https://janw.me/wp/wp-content/themes/parent-theme
// Does not go the the style.css unlike the child theme counterpart

Constants:

WP_HOME         // https://janw.me
WP_SITEURL      // https://janw.me/wp
ABSPATH         // /var/www/janw.me/wp/
WP_CONTENT_DIR  // /var/www/janw.me/www/wp/wp-content
WP_CONTENT_URL  // https://janw.me/wp/wp-content
WP_PLUGIN_DIR   // /var/www/janw.me/wp/wp-content/plugins
WP_PLUGIN_URL   // https://janw.me/wp/wp-content/plugins
WPMU_PLUGIN_DIR // /var/www/janw.me/wp/wp-content/mu-plugins
WPMU_PLUGIN_URL // https://janw.me/wp/wp-content/mu-plugins
UPLOADS         // /var/www/janw.me/wp/wp-content/uploads
// UPLOADS is only used on multisite installs

Theme

get_template_directory()       //  /var/www/wordpress.dev/sandbox/content/themes/child-theme
get_template_directory_uri()   //  https://sandbox.wordpress.dev/content/themes/parent-theme
get_stylesheet_directory_uri() //  https://sandbox.wordpress.dev/content/themes/child-theme
get_stylesheet_uri()           //  https://sandbox.wordpress.dev/content/themes/child-theme/style.css
get_theme_root_uri()           //  https://sandbox.wordpress.dev/content/themes
get_theme_root()               //  /var/www/wordpress.dev/sandbox/content/themes
get_theme_roots()              //  /themes

Plugins

plugins_url()                //  https://sandbox.wordpress.dev/content/plugins
plugin_dir_url(  __FILE__ )  //  https://sandbox.wordpress.dev/content/plugins/plugin-folder/
plugin_dir_path(  __FILE__ ) //  /var/www/wordpress.dev/sandbox/content/plugins/plugin-folder/
plugin_basename(  __FILE__ ) //  plugin-folder/plugin-file.php

Uploads

$wp_upload_dir = wp_upload_dir() // use wp_upload_dir('2013/03'); to set it to march 2013
$wp_upload_dir['path']           //  /var/www/janw.me/www/wp/wp-content/uploads/2013/03
$wp_upload_dir['url']            //  https://janw.me/wp/wp-content/uploads/2013/03
$wp_upload_dir['subdir']         //  /2013/03
$wp_upload_dir['basedir']        //  /var/www/janw.me/www/wp/wp-content/uploads
$wp_upload_dir['baseurl']        //  https://janw.me/wp/wp-content/uploads
$wp_upload_dir['error']          //  should be FALSE or the error message

Multisite

network_admin_url()  //  https://janw.me/wp/wp-admin/
network_site_url()   //  https://janw.me/wp
network_home_url()   //  https://janw.me

Other functions

home_url()      // https://janw.me
site_url()      // https://janw.me/wp
admin_url()     // https://janw.me/wp/wp-admin/        including trailing slash
includes_url()  // https://janw.me/wp/wp-includes/  including trailing slash
content_url()   // https://janw.me/wp/wp-content
get_home_path() // /var/www/janw.me/public_html/  after `admin_init` only
get_rest_url()  // https://janw.me/wp-json/
home_url(add_query_arg(null, null)); // get the absolute current url including the query string

Get full current url

global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );

Source
So this gets the full current url on the frontend.

Leave a Reply

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