WordPress folder functions: all paths lead to WordPress

WordPress offers many ways to access the names of its folders and build new ones. Here is a helpful list with examples performed, to be more clear, from a subfolder located in a hypothetical plugin:

Plugins

Let's start with plugins_url() useful to determine and build url when you write a plugin.

plugins_url ()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/ / If this line is performed by
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/test.php

plugins_url ( ) ; $ R = plugins_url ();
/ / Http://www.miosito.com/wp-content/plugins/

plugins_url ( 'myscript.js' , __FILE__ ) ; $ R = plugins_url ('MyScript.js', __ FILE__);
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/myscript.js

plugins_url ( 'assets' ) ; $ R = plugins_url ('assets');
/ / Http://www.miosito.com/wp-content/plugins/assets

trailingslashit ( plugins_url ( 'assets' ) ) ; $ R = trailingslashit (plugins_url ('assets'));
/ / Http://www.miosito.com/wp-content/plugins/assets/

plugin_dir_url ()

This function is a variant of the above.

1
2
3
4
5
/ / If this line is performed by
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/test.php

plugin_dir_url ( __FILE__ ) ; $ R = plugin_dir_url (__ FILE__);
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/

plugin_dir_path ()

This is substantially similar to plugin_dir_url() , returns the path on the filesystem. Retrieve the path to the file system is useful and necessary for example when we have to perform the include() . The format paths http , however, are useful and necessary when we have to load scripts, styles, css, images and so on can be reached by your browser.

1
2
3
4
5
/ / If this line is performed by
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/test.php

plugin_dir_path ( __FILE__ ) ; $ R = plugin_dir_path (__ FILE__);
/ / / Var/www/clients/client2/web18/web/wp-content/plugins/my_plugin/classes /

In fact can be considered an alias of return trailingslashit( dirname( __FILE__ ) );

plugin_basename ()

1
2
3
4
5
/ / If this line is performed by
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/test.php

plugin_basename ( __FILE__ ) ; $ R = plugin_basename (__ FILE__);
/ / My_plugin / classes / test.php

Themes

Let's see the features related to the themes.

get_theme_root_uri ()

Returns the url of the theme. , che nel nostro caso è http://www.miosito.com/ , e un parametro non considerato passato alla stessa get_theme_root_uri() This function applies a filter theme_root_uri with two additional parameters: the address of the site is stored in the option siteurl , which in our case is http://www.miosito.com/ , and not considered a parameter passed to the same get_theme_root_uri()

1
2
3
4
5
/ / If this line is performed by
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/test.php

get_theme_root_uri ( ) ; $ R = get_theme_root_uri ();
/ / Http://www.miosito.com/wp-content/themes

get_theme_root ()

This is the variation over to the filesystem. Although this uses a filter theme_root .

1
2
3
4
5
/ / If this line is performed by
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/test.php

get_theme_root ( ) ; $ R = get_theme_root ();
/ / / Var/www/clients/client2/web18/web/wp-content/themes

get_theme_roots ()

This returns either a string with the theme folder, if one, or an array of topics.

1
2
3
4
5
/ / If this line is performed by
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/test.php

get_theme_roots ( ) ; $ R = get_theme_roots ();
/ / / Themes

WordPress

These functions return a number of key locations and useful.

home_url ()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/ / If this line is performed by
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/test.php

home_url ( ) ; $ R = home_url ();
/ / Http://www.miosito.com

admin_url ( ) ; $ R = admin_url ();
/ / Http://www.miosito.com/wp-admin/

site_url ( ) ; $ R = site_url ();
/ / Http://www.miosito.com

content_url ( ) ; $ R = content_url ();
/ / Http://www.miosito.com/wp-content

includes_url ( ) ; $ R = includes_url ();
/ / Http://www.miosito.com/wp-includes/

wp_upload_dir ( ) ; $ R = wp_upload_dir ();
/ / This returns an array key pair thus formed
6 ) { array (6) {
] => string ( 61 ) "/var/www/clients/client2/web18/web/wp-content/uploads/2012/04" ["Path"] => string (61) "/ var/www/clients/client2/web18/web/wp-content/uploads/2012/04"
] => string ( 49 ) "http://www.miosito.com/wp-content/uploads/2012/04" ["Url"] => string (49) "http://www.miosito.com/wp-content/uploads/2012/04"
] => string ( 8 ) "/2012/04" ["Subdir"] => string (8) "/ 2012/04"
] => string ( 53 ) "/var/www/clients/client2/web18/web/wp-content/uploads" ["Basedir"] => string (53) "/ var/www/clients/client2/web18/web/wp-content/uploads"
] => string ( 41 ) "http://www.miosito.com/wp-content/uploads" ["Baseurl"] => string (41) "http://www.miosito.com/wp-content/uploads"
] => bool ( false ) ["Error"] => bool (false)
}

Multisite

These are features that were introduced with the release of WordPress 3.0, when WordPress MU (Multisite) was merged with WordPress.

get_admin_url ()

di un dato sito. This supports the filter admin_url and returns the administration folder wp-admin of a given site. Almost all of these functions, in fact, accept (optionally) as the first parameter the ID of the blog.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/ / If this line is performed by
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/test.php

get_admin_url ( ) ; $ R = get_admin_url ();
/ / Http://www.miosito.com/wp-admin/

get_home_url ( ) ; $ R = get_home_url ();
/ / Http://www.miosito.com

get_site_url ( ) ; $ R = get_site_url ();
/ / Http://www.miosito.com

network_admin_url ( ) ; $ R = network_admin_url ();
/ / Http://www.miosito.com/wp-admin/

network_site_url ( ) ; $ R = network_site_url ();
/ / Http://www.miosito.com

network_home_url ( ) ; $ R = network_home_url ();
/ / Http://www.miosito.com

One Response to: " "

  1. April 19, 2012 vik :

    Thanks strategic useful!

Leave a comment

TAG XHTML PERMITS: CODE ENTRY:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL