How to add an About Us blurb to every WordPress blog post

Share this!

screen capture of About Us blurbMany blogs display “About The Author” information below each blog post. In WordPress, many of the recent default themes (twentyten, twentytwelve, and twentythirteen) innately support the display of an author’s name, avatar, and bio — if the author has filled in his or her bio in the dashboard, that is. Even if themes don’t innately support the display of this information, it’s easy to modify the appropriate theme template with template tags (e.g., the_author_meta) to display the information.

But what about displaying an “About Us” blurb below each single blog post? An About Us blurb could contain information about the Web site or the organization behind it, as opposed to information about the author of the post, which, as explained above, is handled elsewhere.

In this article I’ll show you how you can add an About Us blurb that appears below each single blog post.

A function and a filter

We’ll add this “About Us” information by creating a function and calling a filter.

We’ll write the code inside a php file located in the mu-plugins (must-use plugins) folder, directly under the wp-content folder. Note: the mu-plugins folder does not exist by default. You must create it. (Read this page in the WordPress Codex for more information about must-use plugins and the mu-plugins folder.)

Alternatively, you could place this code in the functions.php file of the active theme. However, since “About Us” information is not strictly theme-related, a better practice is to make the code a must-use plugin, in the event a different theme is ever activated. Markup in your theme’s stylesheet file can determine how this content will be displayed.

The code in question uses the the_content() filter.

In this sample, I’m displaying the actual code used (at this writing, anyway) for this blog.

function after_single_blurb($content) {
	if ( is_single() ) {
		$content .= '<div class="about-us">' . "\n";
		$content .= '<h2>About this Web site</h2>' . "\n";
		$content .= '<p>The nSiteful Tech Blog (the official blog of <a target="_blank" href="http://nsiteful.com/">nSiteful Web Builders, Inc.</a> since January of 2013) is where I (Jeff Cohan) and (occasionally) associates will be posting articles of potential interest to like-minded techies, nSiteful clients who are playing active roles in the maintenance of their own Web sites and blogs, and pretty much anyone interested in how Web strategies and tools can help them reach their goals.</p>';
		$content .= "</div><!-- /.about-us -->\n";
	}
	return $content;
}
add_filter( 'the_content', 'after_single_blurb');

Let’s examine the code for the About Us blurb.

I named the function after_single_blurb(), a unique custom function name that doesn’t match any native WordPress function or any other custom function previously named and declared. It has a single parameter, $content, which is the WordPress variable that contains the contents of the post.

Line #2 uses the conditional tag is_single, because I want the blurb to appear only on single-post articles, not on archive pages where the redundancy would be obnoxious.

The next four lines simply concatenate (using the .= php operator) custom content (and appropriate HTML tags) to the content that passed into the function using the $content variable.

On line #8, we return the new, modified content (in the form of the $content variable).

Finally, we call the add_filter function, whose two arguments are (a) the the_content function and (b) after_single_blurb, the custom function that generates the “About Us” content. This way, every time the the_content function is called in a single post, our custom function will be triggered, thus adding the new content.

Get creative with your About Us blurbs.

I hope this article helps someone. Maybe it’s even gotten some wheels turning…

WordPress’ many conditional tags (such as is_single) offer lots of cool customization opportunities.

For example, suppose you want to display a generic “About Us” blurb for all posts by default, but you want to display a special “About Us” blurb, telling readers about how great your online store is, for posts in the “Products” category. Just modify the above function by adding code that uses the is_category() tag with the appropriate argument. (The is_tag() conditional tag will work the same way.)

Or maybe you want different “About Us” blurbs for each category. Your approach would be similar to the above, except you’d probably want to use the php switch control structure.

Of course, you’re not limited to WordPress’ conditional tags when it comes to customizing your custom after-post blurb. With the right dose of knowledge of php, WordPress, and CSS, you can make magic happen.

But I digress.

Let me know what you think of this little technique, and don’t be shy about asking questions or offering suggestions about how to do things differently or better.

Thanks for listening.

Share this!

About JeffCohan.com

The nSiteful Tech Blog (the official blog of nSiteful Web Builders, Inc. since January of 2013) is where I (Jeff Cohan) and (occasionally) associates will be posting articles of potential interest to like-minded techies, nSiteful clients who are playing active roles in the maintenance of their own Web sites and blogs, and pretty much anyone interested in how Web strategies and tools can help them reach their goals.

This entry was posted in Techniques and tagged , by Jeff Cohan. Bookmark the permalink.

About Jeff Cohan

Jeff and his wife, Margie, are the proud parents of Sarah and Jake. Jeff is the founder, president and chief cook and bottle washer of nSiteful Web Builders, Inc., a Web development and Internet Consulting firm. In his spare time, Jeff builds Web sites and Web applications, plays guitar, putters around in his basement woodworking shop, mercilessly spoils his grandchildren, and creates videos from more than two decades of home movies. His current video project is an extended montage of people (mainly family members) asking him to stop filming them.

Leave a Reply

Your email address will not be published. Required fields are marked *