Top 5 Most Useful WordPress Functions & Plugins

HL News • February 17, 2014

We’ve been using WordPress as our go-to CMS (Content Management System) since 2009, or version 2.8.6 in WordPress terms, and have learned a few tricks along the way. WordPress is a great platform offering robust development and endless customization’s.

HERE IS THE LIST OF OUR TOP 5 MOST USEFUL FUNCTIONS AND PLUGINS:

1. Send Email From Address Other Than WordPress
By default, you can’t modify the FROM email address in WordPress. This goes for emails that are sent to you, and those sent to your user when they submit a lost password request.
But if you want to be able to easily change it, whether you are developing a site for a client, or are just working on your personal blog, keep reading.

This function, and optional custom plugin, will solve this issue in no time. If you would rather update the WordPress Mail function, follow this link.

You can easily implement this solution in one of two ways; add a function to your theme functions.php file, or add it as a standalone plugin. Our preferred method is using this solution as a standalone plugin, because it will travel with you no matter what theme you are using.

-> Code for functions.php
add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');
function new_mail_from($old) {
return '[email protected]';
}
function new_mail_from_name($old) {
return 'Your Blog Name';
}

-> Code for Plugin (recommended method)

/*
Plugin Name: Change "WordPress" sender mail
Plugin URI: http://heartlandlogic.com
Description: Change the default address that WordPress sends its email from.
Version: 1.0
Author: Heartland Web Group
Author URI: http://www.heartlandwebgroup.com
*/
if ( !function_exists('add_action') ) {
header('Status: 403 Forbidden');
header('HTTP/1.1 403 Forbidden');
exit();
}
if ( !class_exists('wp_mail_from') ) {
class wp_mail_from {

function wp_mail_from() {
add_filter( 'wp_mail_from', array(&$this, 'fb_mail_from') );
add_filter( 'wp_mail_from_name', array(&$this, 'fb_mail_from_name') );
}
// new name
function fb_mail_from_name() {
$name = 'Your Site Name Here';
// alternative the name of the blog
// $name = get_option('blogname');
$name = esc_attr($name);
return $name;
}

// new email-adress
function fb_mail_from() {
$email = '[email protected]';
$email = is_email($email);
return $email;
}
}
$wp_mail_from = new wp_mail_from();
}
?>
Once you have implemented your preferred method, send a test email from one of your contact forms to see the change in action. It’s as simple as that.

2. Change “Posts” Tab To Display A Different Title

Many times your clients will only have one type of blog and “Posts” may not be explanatory enough. So, in those instances, you can rename the default “Posts” title to “News” or “Blog” or something that might be more intuitive for your client. As we all know, creating an intuitive client-focused UX is best so as to avoid a bazillion questions later. Mind you, this is not trying to replace “Custom Post Types”, (see the official WordPress site for details on CPT’s), but rather we are just renaming what WordPress gives us with some simple code for those instances where there is only one type of post.

Renaming the Posts menu label consists of changing the menu item, as well as the post label. In the code below we have renamed Posts to Blog. Of course you can rename Posts to anything you want – simply replace every instance of Blog in the code below with your desired label. All you need to do is paste this into your functions.php file and once again, it’s as simple as that!

function heartlandlogic_change_post_label() {
global $menu;
global $submenu;
$menu[5][0] = 'Blog Posts';
$submenu['edit.php'][5][0] = 'Blog Posts';
$submenu['edit.php'][10][0] = 'Add Blog Post';
$submenu['edit.php'][16][0] = 'Blog Post Tags';
echo '';
}
function heartlandlogic_change_post_object() {
global $wp_post_types;
$labels = &$wp_post_types['post']->labels;
$labels->name = 'Blog Posts';
$labels->singular_name = 'Blog Post';
$labels->add_new = 'Add Blog Post';
$labels->add_new_item = 'Add Blog Post';
$labels->edit_item = 'Edit Blog Post';
$labels->new_item = 'Blog Post';
$labels->view_item = 'View Blog Posts';
$labels->search_items = 'Search Blog Posts';
$labels->not_found = 'No Blog Posts found';
$labels->not_found_in_trash = 'No Blog Posts found in Trash';
}
add_action( 'admin_menu', 'heartlandlogic_change_post_label' );
add_action( 'init', 'heartlandlogic_change_post_object' );

*NOTE: The best practice is to paste the above code into a site-specific plugin so it travels with you, no matter what theme you are using. To learn more about site-specific plugins, there are good articles on SearchEnginePeople.com and OttoPress and OneExtraPixel.

3. Change the Default Gravatar in WordPress

Keep up your clients branding efforts! Get rid of that unsightly ‘Mystery man’ avatar and replace it with a custom branded Gravatar to give your clients site a unique, and branded, touch. All you have to do is paste the following code in your functions.php file:

add_filter( 'avatar_defaults', 'newgravatar' );

function newgravatar ($avatar_defaults) {
$myavatar = get_bloginfo('template_directory') . '/images/gravatar.png';
$avatar_defaults[$myavatar] = "YourName";
return $avatar_defaults;
}

Be sure to upload your custom image to your theme’s image folder. Also, name the Gravator the same as their brand name. Once you’ve uploaded the code and image, go to WP-Admin » Settings » Discussion and your Gravatar will show up as one of the options.

4. Change Excerpt Length

By default in WordPress, the excerpt length is capped at 55 words. But sometimes that’s too long, sometimes it’s too short. Because WordPress is so awesome, you can customize the length to fit your needs with this short little function:

function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');

Just change 100 to the length you like, paste in your functions.php file and you’re good to go!

5. Hide Email from SpamBots

I hate spam. My clients hate spam. This function shows you how to convert email address characters to HTML entities to block those pesky spam bots.

Add to functions.php (or use in a site-specific plugin – recommended method):

// Hide Email from Spam Bots using a short code place this in your functions file
function HideMail($atts , $content = null ){
if ( ! is_email ($content) )
return;

return ''.antispambot($content).'';
}

/ / add shortcode functionality:
add_shortcode( 'email','HideMail');

/ / optional: add shortcode functionality to widget area:
add_filter('widget_text', 'do_shortcode');

Then use the shortcode in posts/pages/widgets:
[email][email protected][/email]

Or embed it using PHP code in templates:

Stay tuned for our next post about the 5 most useful functions when developing a Child Theme!