WordPress – How to use WordPress settings in your theme
One of the most powerful WordPress functions you will get to use is: bloginfo().
You can most likely tell that WordPress’s bloginfo() function will return some information regarding your blog. I’ve listed all of the command you can feed bloginfo() below.
name = Testpilot description = Just another WordPress blog admin_email = admin@example url = http://example/home wpurl = http://example/home/wp stylesheet_directory = http://example/home/wp/wp-content/themes/child-theme stylesheet_url = http://example/home/wp/wp-content/themes/child-theme/style.css template_directory = http://example/home/wp/wp-content/themes/parent-theme template_url = http://example/home/wp/wp-content/themes/parent-theme atom_url = http://example/home/feed/atom rss2_url = http://example/home/feed rss_url = http://example/home/feed/rss pingback_url = http://example/home/wp/xmlrpc.php rdf_url = http://example/home/feed/rdf comments_atom_url = http://example/home/comments/feed/atom comments_rss2_url = http://example/home/comments/feed charset = UTF-8 html_type = text/html language = en-US text_direction = ltr version = 3.1
I’m guessing since you are here you are wondering how can you use bloginfo() in your theme and why should you care?
The thing I tend to use bloginfo() for is making sure that no matter where on the site, things like my CSS file location, my home page and theme files are always calculated properly. One of the things I see most often with new WordPress users is that they use relative paths to files like CSS and images. While this might work in static sites, it doesn’t really work all that well in dynamically creates site like a WordPress Website.
Here’s an example:
Notice how I highlighted that the url has several sub folders – “/category/operating-system/active-directory-2003”. If your theme would have used relative paths for the logo and the encompassing link you would have noticed that the logo wouldn’t show up and then link would be most likely broken.
What I normally see people do to fix this issue is just put in Fully Qualified Paths for things like the logo and certain links. In my opinion not only does this add extra bloat to the website it also kind of defeats the dynamic nature of WordPress! Because I tend to create offline themes first and then move it to a online Webserver. If you didn’t use bloginfo() for the links you will have to do a bunch of extra manual changes where ever you hard coded things. This causes extra headaches and unneeded work.
Using my website as an example you can see I use bloginfo() to fill in the anchor link “Url”very easily. I’ve also told it display the Logo image that is located in the template directory.
Another thing I have seen is a person is wanting to make a slightly modified theme for say Christmas. If you were to copy the theme, rename the folder and activate then new theme, all your hard coded links would no longer work or still point to the old theme location!
I recommend getting into a habit of making your themes with built in WordPress functions like bloginfo(). It will save you time and fustration. You will also know that you can pickup your theme and move it where ever you want and you don’t have to worry that the theme folder is even named the same.
Here’s a listing of ALL the settings you can use with “bloginfo()”. http://codex.wordpress.org/Function_Reference/bloginfo