WordPress Tutorial The difference between the function site_url (), Home_url (), bloginfo (' url ')

Source: Internet
Author: User
Tags wordpress blog



In WordPress plugin and theme development often need to get a variety of URL path, WordPress provides the following centralized method to obtain the URL path:



Plugins_url ()-the URL of the plugin directory (for example: Http://www.hujuntao.com/wp-content/plugins)
Includes_url () URL of the-includes directory (for example: Http://www.hujuntao.com/wp-includes)
Content_url () URL of the-content directory (for example: http://www.hujuntao.com/wp-content)
Admin_url () URL of the-admin directory (for example: http://www.hujuntao.com/wp-admin/)
Site_url ()-The URL of the current Web site (for example: http://www.hujuntao.com)
Home_url ()-The URL of the home page of the current website (for example: http://www.hujuntao.com)



There are many ways to get the home address: Site_url (), Home_url (), bloginfo (' url '), get_bloginfo (' url '), Get_site_url (), Get_home_url (). What is the difference between them?
Let's first recognize the two functions of Site_url () and Home_url ().



Site_url () and Home_url () are very similar and easy to confuse. Site_url () returns the SiteURL field value from the Wp_options table in the database. This is the URL that points to the WordPress core file, which is your WordPress installation path. If your WordPress core file is in a subdirectory of your server, such as/wordpress, then the value of Site_url () will be http://www.hujuntao.com/wordpress. In Control Panel ==>> settings ==>> WordPress address (URL) modification. (Do not modify in the case of non-forced, generally after the successful installation, this value is automatically generated.) Modify the wrong address will cause the page can not open, background management can not go in, this situation can only be repaired by modifying the database. )



Home_url () Gets the value of the home field from the Wp_option table. This address is the URL where you want to access your WordPress website. For example, if your wordpres core file is placed in the/wordpress directory, but you want your URL to be http://www.hujuntao.com, set the value of home to http://www.hujuntao.com. Set the ==>> site address (URL) in Control Panel ==>>.



If your blog is installed in the same directory as the two function to obtain the same value, in the plug-in and theme development for the use of compatibility, so in the choice of time need to be cautious.



Generally speaking Home_url () is the home address, mainly used in the need to return to the home page. such as the logo link, "Bread crumbs" of the "home" link and so on.
Site_url () wordpress installation path, mainly used in obtaining local file path.



Figure out these two functions, and then look at Bloginfo ().
Bloginfo is used to get information about blogs, including home page, installation path address.
The following are the available parameters for Bloginfo ():


  1. Name = Testpilot
  2. Description = Just another WordPress blog
  3. Admin_email = [email protected]
  4. URL = http://example/home
  5. Wpurl = http://example/home/wp
  6. Stylesheet_directory = Http://example/home/wp/wp-content/themes/child-theme
  7. Stylesheet_url = Http://example/home/wp/wp-content/themes/child-theme/style.css
  8. Template_directory = Http://example/home/wp/wp-content/themes/parent-theme
  9. Template_url = Http://example/home/wp/wp-content/themes/parent-theme
  10. Atom_url = Http://example/home/feed/atom
  11. Rss2_url = Http://example/home/feed
  12. Rss_url = Http://example/home/feed/rss
  13. Pingback_url = http://example/home/wp/xmlrpc.php
  14. Rdf_url = HTTP://EXAMPLE/HOME/FEED/RDF
  15. Comments_atom_url = Http://example/home/comments/feed/atom
  16. Comments_rss2_url = Http://example/home/comments/feed
  17. CharSet = UTF-8
  18. Html_type = text/html
  19. Language = en-US
  20. Text_direction = LTR
  21. Version = 3.1


where Bloginfo (' url ') = home address; Bloginfo (' wpurl ') = wordpress installation path;



It's easy to figure out what's left of this function.
WordPress's Bloginfo () and Get_bloginfo () functions are similar to displaying information about a user's blog, usually from the user's content in the "My Configuration" and "Settings > general" Menus in the background of the WordPress website. The difference is that bloginfo () outputs the result directly and can be used in any area of the page template, while Get_bloginfo () returns a data!
Use Get_site_url (), get_bloginfo (' url '), Get_home_url () when you need to return a value;

If you want to output the value directly then use Site_url (), bloginfo (' url '), Home_url ();

Let's summarize here:
Get home Address ==> Home_url (), bloginfo (' url '), get_bloginfo (' url '), Get_home_url (). Home_url () 3.0 added function, in order to be compatible with the old version recommended to use Bloginfo ();
Get the installation path ==> site_url (), Bloginfo (' Wpurl '), Get_bloginfo (' Wpurl '), Get_site_url ().



If you need to return a value ==> get_bloginfo (' url '), Get_home_url ()/get_bloginfo (' Wpurl '), Get_site_url ()
If you want to output the value directly ==>



WordPress Tutorial The difference between the function site_url (), Home_url (), bloginfo (' url ')


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.