{"id":2362,"date":"2019-11-25T14:59:51","date_gmt":"2019-11-25T14:59:51","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2362"},"modified":"2025-12-03T20:40:21","modified_gmt":"2025-12-03T20:40:21","slug":"wordpress-paths","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/wordpress\/files-wordpress\/wordpress-paths","title":{"rendered":"WordPress Paths"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">WordPress root<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Homepage URL<\/h5>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $HomeUrl = home_url();\n  \/\/ \"https:\/\/www.example.com\" or \"https:\/\/www.example.com\/mywordpressfolder\"\n\n  $HomeUrl = home_url('\/');\n  \/\/ \"https:\/\/www.example.com\/\" or \"https:\/\/www.example.com\/mywordpressfolder\/\"\n\n  $HomeUrl = home_url('\/mypage');\n  \/\/ \"https:\/\/www.example.com\/mypage\" or \"https:\/\/www.example.com\/mywordpressfolder\/mypage\"<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Reirect to a page<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  wp_redirect( home_url( '\/' ) );\n  \/\/wp_redirect( home_url( '\/my_page_name' ) );    \/\/If you want to redirect to a specific page\n  die();<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Site WP install URL<\/h5>\n\n\n\n<p>The URL of the WordPress install. Usually identical to using site_url(), but not necessarily! User home_url() generally.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $SiteUrl = site_url();\n  \/\/ \"https:\/\/www.example.com\" or \"https:\/\/www.example.com\/mywordpressfolder\"\n\n  $SiteUrl = site_url('\/');\n  \/\/ \"https:\/\/www.example.com\/\" or \"https:\/\/www.example.com\/mywordpressfolder\/\"\n\n  $SiteUrl = site_url('\/mypage');\n  \/\/ \"https:\/\/www.example.com\/mypage\" or \"https:\/\/www.example.com\/mywordpressfolder\/mypage\"<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">URL to WP admin area<\/h5>\n\n\n\n<p>For ap-admin you should use site_url(), thats the correct usage!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $AdminAreaUrl = site_url('\/wp-admin');<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">WordPress root &#8211; Server filesystem<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  $SiteRootFilePath = ABSPATH;\n  \/\/  \/var\/www\/vhosts\/example.com\/public_html\/\n  \/\/or for a wordpress site installed in a sub directory:\n  \/\/  \/var\/www\/vhosts\/example.com\/public_html\/mysubdirectory\/\n\n  get_home_path()      &lt;&lt;This is a backend function, it only works if the necessary wordpress include files are present. ABSPATH is usually better (its a define that just works)\n  \/\/  \/var\/www\/vhosts\/example.com\/httpdocs\/<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">WordPress Theme<\/h4>\n\n\n\n<p>get_stylesheet_directory_uri() is better because get_template_directory_uri() will get the main theme, not the child theme if being used<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Return full URI path (including https:\/\/)<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>$MyImagePath = get_stylesheet_directory_uri() . \"\/mysubfolder\/myimage.jpg\";<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Return path on local server<\/h5>\n\n\n\n<p>(e,g, \/home\/user\/public_html\/wp-content\/themes\/my_theme)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (!is_file(get_stylesheet_directory() . \"\/mysubfolder\/myimage.jpg\"))\n  {\n  }<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Themes directory<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  theme_url()\n  \/\/  https:\/\/www.example.com\/wp-content\/themes<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Other theme path functions<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>get_template_directory_uri()\nget_stylesheet_uri()\nget_theme_root_uri()\nget_theme_root()\nget_theme_roots()\nget_template_directory()<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">WordPress Plugin<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Plugin&#8217;s root directory<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  plugins_url()\n  \/\/  https:\/\/example.com\/wp-content\/plugins<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">This plugin<\/h5>\n\n\n\n<p>URL<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  plugin_dir_url( __DIR__ )\n  \/\/  https:\/\/example.com\/wp-content\/plugins\/my-plugin-name\/\n  \/\/THIS DOESNT'T ALWAYS SEEM TO WORK, SOMETIMES NEED TO USE FILE INSTEAD - CHECK BEFORE YOU COMMIT\n\n  plugin_dir_url( __FILE__ )\n  \/\/  https:\/\/example.com\/wp-content\/plugins\/my-plugin-name\/folder-this-file-is-in\/<\/code><\/pre>\n\n\n\n<p>Filesystem path<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  plugin_dir_path( __DIR__ )\n  \/\/  \/var\/www\/vhosts\/example.com\/httpdocs\/wp-content\/plugins\/my-plugin_name\/\n\n  plugin_dir_path( __FILE__ )\n  \/\/  \/var\/www\/vhosts\/example.com\/httpdocs\/wp-content\/plugins\/my-plugin_name\/folder-this-file-is-in\/<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Path relative to wordpress plugins root directory<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  plugin_basename( __DIR__ )\n  \/\/  my-plugin_name\/folder-this-file-is-in\n    \n  plugin_basename( __FILE__ )\n  \/\/  my-plugin_name\/folder-this-file-is-in\/this-files-name.php<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">The current file<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Filesystem path<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  plugin_dir_path( __DIR__ )\n  \/\/  \/var\/www\/vhosts\/example.com\/httpdocs\/wp-content\/plugins\/my-plugin_name\/\n\n  echo plugin_dir_path( __FILE__ );\n  \/\/Example output\n  \/\/  \/var\/www\/vhosts\/my-domain-name.com\/httpdocs\/wp-content\/plugins\/my-plugin_name\/the-directory-this-file-is-in\/<\/code><\/pre>\n\n\n\n<p>(The \u201cplugin\u201d part of the name is misleading \u2013 it can be used for any file, plugin file or not) <\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Filesystem path \u2013 web server referenced<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  echo ( __DIR__ );\n  \/\/Example output\n  \/\/  \/home\/websiteusername\/public_html\/wp-content\/plugins\/my-plugin_name\/the-directory-this-file-is-in\n\n  echo ( __FILE__ );\n  \/\/Example output\n  \/\/  \/home\/websiteusername\/public_html\/wp-content\/plugins\/my-plugin_name\/the-directory-this-file-is-in\/this-file-name.php<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Upload directory<\/h4>\n\n\n\n<p>If use date based folder is enabled for your wordpress site then a folder will be created for the current year\/month if it doesn&#8217;t exist already<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $UploadDirectory = wp_upload_dir();\n  \/\/  Returns an array:\n  \/\/  $UploadDirectory&#91;'path']  \/var\/www\/vhosts\/example.com\/httpdocs\/wp-content\/uploads\n  \/\/  $UploadDirectory&#91;'url']  https:\/\/example.com\/wp-content\/uploads \n  \/\/  $UploadDirectory&#91;'subdir']  \n  \/\/  $UploadDirectory&#91;'basedir']  \/var\/www\/vhosts\/example.com\/httpdocs\/wp-content\/uploads\n  \/\/  $UploadDirectory&#91;'baseurl']  https:\/\/example.com\/wp-content\/uploads \n  \/\/  $UploadDirectory&#91;'error']  \n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Creating your own folder in the upload directory<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $UploadDirectory = wp_upload_dir(); \n  $OurUploadDirectory = $UploadDirectory&#91;'basedir'] . '\/my-folder-name';\n  if (!file_exists($OurUploadDirectory))\n    wp_mkdir_p($OurUploadDirectory);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Other WordPress Directories<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Admin directory<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  admin_url()\n  \/\/  https:\/\/www.example.com\/wp-admin<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Includes directory<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  includes_url()\n  \/\/ https:\/\/www.example.com\/wp-includes<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Content directory<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  content_url()\n  \/\/  https:\/\/www.example.com\/wp-content<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>WordPress root Homepage URL Reirect to a page Site WP install URL The URL of the WordPress install. Usually identical to using site_url(), but not necessarily! User home_url() generally. URL to WP admin area For ap-admin you should use site_url(), thats the correct usage! WordPress root &#8211; Server filesystem WordPress Theme get_stylesheet_directory_uri() is better because [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[178,198,386],"tags":[],"class_list":["post-2362","post","type-post","status-publish","format-standard","hentry","category-files-wordpress","category-links","category-urls-wordpress"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2362"}],"version-history":[{"count":35,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2362\/revisions"}],"predecessor-version":[{"id":5228,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2362\/revisions\/5228"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}