Advertisement

This will be a growing list of my, often used, code snippets. I usually store them in Coda for ease of access but I figure I can put them up here as well for anyone else who might need/want them. Most are created to speed up my development process or reduce the number of database calls in an effort to speed things up. If you have any suggestions for the list let me know.

Bloginfo Stored in an Array

Typical themes, including the ones that come with WordPress, make calls to the database every time they need information about the blog. This can range from the blog name to the URL for the RSS feed of the blog’s comments. This array, stored in the functions file, will reduce the number of calls made to the database for the most commonly used bits of data.

The following goes in your functions.php file.

global $bloginfo;
$bloginfo = array(
	'name'					=> get_bloginfo('name'),
	'description'			=> get_bloginfo('description'),
	'url'					=> get_bloginfo('url'),
	'wpurl'					=> get_bloginfo('wpurl'),
	'stylesheet_directory'	=> get_bloginfo('stylesheet_directory'),
	'stylesheet_url'		=> get_bloginfo('stylesheet_url')
);

Then, any time you need to reference the array within a function or a template file just add global $bloginfo and then you can echo or use it in your code with $bloginfo['name'].

Share this post!

Advertisement