WordPress Development: Plug-ins VS Functions

Est. Reading Time: 4 minutes

There are thousands of plugins available for WordPress, which is awesome for non-coders.  The issue with many of these plugins is the bulk code it produces is highly unnecessary when you consider most functionality is already available for use in a fresh installation of WordPress. Plug-ins also have to be reconfigured across sites–integrating these functions into your template eases the portability of your site’s theme while maintaining functionality. On a recent project, we discussed this integration as a standard for blog development, which is a significant advantage when you consider the process of pushing out releases.

Consider the following 3 plug-ins:


These are pretty  commonly used methods of displaying blog posts and content.  Together, these 3 plug-ins only take up 500Kb of data–however, everything you need is already in WordPress if you know the lay of the land. The three functions below can do all the same things with just a copy+paste into your functions-file, usually located at:


These are pretty simple to modify or tweak as needed, whether it be the code in PHP or the markup/styles. Oh, and these replacement functions only take up a tiny 1.64Kb!


	function popularPosts($num) {
		global $wpdb;
		$posts = $wpdb->get_results("SELECT comment_count, ID, post_title, post_date FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , $num");
		foreach ($posts as $post) {
			$title = $post['post_title'];
			$count = $post['comment_count'];
			$date = $post['post_date'];
			if($count!=0) echo '<li><a href="' . get_permalink($id) . '" title="' . $title . '">' . $title . '</a><br /><div class="post-date">'.$date.'</div></li>';
	function recentPosts($num){
		$args = array('numberposts'=>$num);
		$recent_posts = wp_get_recent_posts($args);
		foreach($recent_posts as $post){
			$date = $post['post_date'];
			echo '<li><a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' .   $post["post_title"].'</a><div class="post-date">'.$date.'</div></li>';
	function recentComments($num){
		global $wpdb;
		$comments = $wpdb->get_results("SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT ".$num);
		foreach ($comments as $comment)	echo '<li><strong>'.ucwords(strip_tags($comment->comment_author)) ."</strong> commented on " . "<a href=\"" . get_permalink($comment->ID)."#comment-" . $comment->comment_ID . "\" title=\"on ".$comment->post_title . "\">" . $comment->post_title ."</a></li>";

Once you have these in functions.php, it is easy to call the functions from the sidebar or other locations of the template files.


  • The functions above would need to go inside of individual unordered list tags as they are currently marked up for the sidebar.
  • The function require to pass a numeric parameter representing the number of posts/comments to return.

Example Usage:

This is an example of how to setup your ‘sidebar.php’ file to make use of these functions, Plugin-free.

<div id="sidebar">
	<div class="search" align="center">
		<?php get_search_form() ?>
		echo '<div class="tabs">';
		echo '<div id="popular-posts">';
		echo '<h2>Popular</h2><ul>';
		echo '</ul></div>';
		echo '<div id="recent-posts">';
		echo '<h2>Recent</h2><ul>';
		echo '</ul></div>';
		echo '<div id="recent-comments">';
		echo '<h2>Comments</h2><ul>';
		echo '</ul></div>';
		//Get dynamic toolbar managed in WordPress Dashboard
		if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('tabs')){echo '</div>';}
		if(function_exists('dynamic_sidebar') && dynamic_sidebar('Sidebar Widgets')) : else : endif;