{"id":1177,"date":"2012-02-05T22:01:41","date_gmt":"2012-02-05T22:01:41","guid":{"rendered":"http:\/\/gr-01.de\/whitepapers.grafik-und-redaktion.de\/?p=1177"},"modified":"2013-06-03T03:43:30","modified_gmt":"2013-06-03T01:43:30","slug":"paths-for-building-wordpress-themes-or-plugins","status":"publish","type":"post","link":"https:\/\/whitepapers.grafik-und-redaktion.de\/?p=1177","title":{"rendered":"Paths For Building WordPress Themes or Plugins"},"content":{"rendered":"<p>(Quelle: <a href=\"http:\/\/computeraxe.com\/paths-building-wordpress-themes-plugins\/\" target=\"_blank\">computeraxe.com\/paths-building-wordpress-themes-pl&#8230;<\/a>) When tinkering with the code that runs WordPress it\u2019s very important to get the correct path to a file. Of course it is or else the files can\u2019t be found and your new functionality won\u2019t work.<\/p>\n<p>According to the Codex<\/p>\n<blockquote><p>In Version 2.6, users were given the ability to move their \/wp-content\/ directory to anywhere they want, and many users already keep all WordPress files (like \/wp-admin\/ and \/wp-includes\/) in an unusual place.<\/p><\/blockquote>\n<p>In case you\u2019ve moved the files for your WP installation, you probably have a good handle on paths and how to traverse them. For those who don\u2019t, it can be a hair-pulling experience to find the right path. Once the right path is found, work can continue.<\/p>\n<h2>WordPress Paths<\/h2>\n<p>To help avoid those <em>DUH! <\/em>moments, here are some functions and constants that WordPress has defined regarding paths. Once you\u2019re familiar with these functions, writing useful and working code should become easier. Optional parameters may be of use in modifying the output for several of the following templates, including $path, $file or $scheme.<\/p>\n<dl>\n<dt>plugin_basename()<\/dt>\n<dd>Usage: plugin_basename(__FILE__); Returns: the name of the plugin and file, such as \u201cmyPlugin\/myPlugin.php\u201d<\/dd>\n<dt>get_theme_root()<\/dt>\n<dd>Usage: get_theme_root(); Returns: path to themes directory. <strong>No<\/strong> trailing slash.<\/dd>\n<dt>get_theme_root_uri()<\/dt>\n<dd>Usage: get_theme_root_uri(); Returns: URI for themes directory. <strong>No<\/strong> trailing slash.<\/dd>\n<dt>get_theme_roots()<\/dt>\n<dd>Usage: get_theme_roots(); Returns: Themes directory with a <em>leading<\/em> slash, like \u201c\/themes\u201d.<\/dd>\n<dt>site_url()<\/dt>\n<dd>Usage: site_url(); Returns: Site directory with <strong>no<\/strong> trailing slash.<\/p>\n<p><a href=\"http:\/\/www.site.com\" class=\"autohyperlink\" target=\"_blank\">www.site.com<\/a> OR <a href=\"http:\/\/www.site.com\/wordpress\" class=\"autohyperlink\" target=\"_blank\">www.site.com\/wordpress<\/a><\/dd>\n<dt>admin_url()<\/dt>\n<dd>Usage: admin_url(); Returns: Admin directory with trailing slash.<\/p>\n<p><a href=\"http:\/\/www.site.com\/wp-admin\/\" class=\"autohyperlink\" target=\"_blank\">www.site.com\/wp-admin\/<\/a><\/dd>\n<dt>content_url()<\/dt>\n<dd>Usage: content_url(); Returns: Content directory with trailing slash.<\/p>\n<p><a href=\"http:\/\/www.site.com\/wp-content\/\" class=\"autohyperlink\" target=\"_blank\">www.site.com\/wp-content\/<\/a><\/p>\n<\/dd>\n<dt>plugins_url()<\/dt>\n<dd>Usage: plugins_url(); Returns: Plugins directory with trailing slash.<\/p>\n<p><a href=\"http:\/\/www.site.com\/wp-content\/plugins\/\" class=\"autohyperlink\" target=\"_blank\">www.site.com\/wp-content\/plugins\/<\/a><\/dd>\n<dt>includes_url()<\/dt>\n<dd>Usage: includes_url(); Returns: Includes directory with trailing slash.<\/p>\n<p><a href=\"http:\/\/www.site.com\/wp-includes\/\" class=\"autohyperlink\" target=\"_blank\">www.site.com\/wp-includes\/<\/a><\/dd>\n<dt>home_url()<\/dt>\n<dd>Usage: home_url(); Returns: Home directory with <strong>no<\/strong> trailing slash.<\/p>\n<p><a href=\"http:\/\/www.site.com\" class=\"autohyperlink\" target=\"_blank\">www.site.com<\/a><\/p>\n<\/dd>\n<dt>ABSPATH (constant)<\/dt>\n<dd>Usage: ABSPATH. Returns: Home directory with <strong>no<\/strong> trailing slash.<\/dd>\n<dt>TEMPLATEPATH (constant)<\/dt>\n<dd>Usage: TEMPLATEPATH. Returns: Path to current theme with <strong>no<\/strong> trailing slash.<\/dd>\n<\/dl>\n<p>There are a few more functions for multisite installations and <a title=\"Directories for older versions of WP\" href=\"http:\/\/codex.wordpress.org\/Determining_Plugin_and_Content_Directories#Backwards-compatibility_Code\">backwards capability<\/a> specified in the Codex.<\/p>\n<h2>PHP Paths<\/h2>\n<p>Some PHP functions worth noting &#8211;<\/p>\n<ul>\n<li>__FILE__ returns the filename of the script that is currently being run<\/li>\n<li>dirname() returns parent directory\u2019s path for a given filename with <strong>no<\/strong> trailing slash<\/li>\n<li>basename() returns the filename component of path without any parent directories<\/li>\n<li>getcwd() returns current working directory<\/li>\n<\/ul>\n<p>Use the functions or constants indicated to build your paths instead of hard-coding them. You\u2019ll save yourself a LOT of trouble when it comes time to move your WordPress installation to a new server or directory.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(Quelle: <a href=\"http:\/\/computeraxe.com\/paths-building-wordpress-themes-pl&#8230;\" class=\"autohyperlink\" target=\"_blank\">computeraxe.com\/paths-building-wordpress-themes-pl&#8230;<\/a>) When tinkering with the code that runs WordPress it\u2019s very important to get the correct path to a file. Of course it is or else the files can\u2019t be found and your new functionality won\u2019t work. According to &hellip; <a href=\"https:\/\/whitepapers.grafik-und-redaktion.de\/?p=1177\">Weiterlesen &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76,77,57],"tags":[17],"_links":{"self":[{"href":"https:\/\/whitepapers.grafik-und-redaktion.de\/index.php?rest_route=\/wp\/v2\/posts\/1177"}],"collection":[{"href":"https:\/\/whitepapers.grafik-und-redaktion.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/whitepapers.grafik-und-redaktion.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/whitepapers.grafik-und-redaktion.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/whitepapers.grafik-und-redaktion.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1177"}],"version-history":[{"count":4,"href":"https:\/\/whitepapers.grafik-und-redaktion.de\/index.php?rest_route=\/wp\/v2\/posts\/1177\/revisions"}],"predecessor-version":[{"id":3162,"href":"https:\/\/whitepapers.grafik-und-redaktion.de\/index.php?rest_route=\/wp\/v2\/posts\/1177\/revisions\/3162"}],"wp:attachment":[{"href":"https:\/\/whitepapers.grafik-und-redaktion.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/whitepapers.grafik-und-redaktion.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/whitepapers.grafik-und-redaktion.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}