WordPress: Add Title to IMG tag using Get The Image plugin

This image is a screenshot from Get The Image plugin.

This image is a screenshot from Get The Image plugin.

Get The Image plugin from Justin Tadlock is awesome, a script that can grab an image by custom field input, WordPress’ featured image, post attachment, or extracting it from the post’s content.

Recently, someone asked about how to add Title to IMG tag. We know ALT attributes in IMG tag, but IMG tag also support Title attributes as well. These two attributes supposed to describe the image in words and impact image search rankings. ALT attribute should describe what the image is about, while Title should follow the rules of the regular title.

Get The Image only have ALT attribute, we are adding Title attribute by changing following code
1. Open get-the-image.php with Text Editor. I’m using Text Wrangler on Mac
2. Find following code, it’s in line 459-460 on Text Wrangler. Change it from

/* Add the image attributes to the <img /> element. */
	$html = '<img src="' . $image['src'] . '" alt="' . esc_attr( strip_tags( $image_alt ) ) . '" class="' . esc_attr( $class ) . '"' . $width . $height . ' />';


/* Add the image attributes to the <img /> element. */
    $html = '<img src="' . $image['src'] . '" alt="' . esc_attr( strip_tags( $image_alt ) ) . '" title="' . esc_attr( apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) ) . '" class="' . esc_attr( $class ) . '"' . $width . $height . ' />';

WordPress: How to Display Date and Time with User-preferred Formatting

We set Date Format and Time Format in WordPress General Setting and we want to display that date on WordPress template. The Date Format and the Time Format settings allow us to set Date and Time to any format we wants, it also easier to use with localization. Use following code in WordPress template

<?php the_time(get_option('date_format')); ?>


<?php the_time(get_option('time_format')); ?>

How to Modify get_comment_author_link to Open Comment Authors Website on new Window

wordpress-logo-notext-rgbBy default, get_comment_author_link  redirects the user to the site which was entered by comment author when they wrote comment in same window of our site. What if we want this to open on new window?

Add following code to functions.php in your live theme directory

//Display website on new window when readers click Commenter's name 
add_filter( "get_comment_author_link", "pxzoom_modifiy_comment_author_anchor" );
function pxzoom_modifiy_comment_author_anchor( $author_link ){
    return str_replace( "<a", "<a target='_blank'", $author_link );

WordPress: Conditional tag to check a specific menu

Following conditional tag usually use in this filter function, wp_nav_menu_items

if( $args->theme_location == 'primary' )


if( $args->theme_location == 'secondary' )


if( $args->theme_location == 'primary' )

For an example, I want to add search box to Primary Menu in WPZOOM theme name Videozoom. Conditional tag above make sure the search only show in a specif menu (Primary)
1. Open functions.php
2. Add following code to functions

add_filter('wp_nav_menu_items','search_box_function', 10, 2);
function search_box_function( $nav, $args ) {
if( $args-&gt;theme_location == 'primary' )
return $nav."<li class='menu-header-search'><form role='search' action='".get_bloginfo('url')."' id='searchform' method='get'><input id="s" type="text" name="s" placeholder="Search" /><input id="searchsubmit" type="submit" value="Search" />";

return $nav;

How to add widgetized and custom sidebars on WordPress theme

WordPress themes are usually come with Widgetized sidebars where you can drag and drop widgets. It’s okay when we don’t need more widgetized sidebars to the theme, but we probably think to add more when we think widgetized sidebar solution to your customization problem, for instance you want to add a banner ad to header area or footer area. This requires coding solution in few themes and each theme could have different solution.
This plugin, Custom Sidebar provides easy solution. The installation is straightforward, we can download from wordpress.org,  upload it to wp-content/plugins directory and activate the plugin in the plugin menu panel or Add New and search Custom Sidebar from the plugin menu panel

Now, we want to add new widgetized sidebar (or in this case widgetized area).  I want to show a Banner Ad with Text Widget dragged and dropped to the new widgetized sidebar/area.

1. Create new sidebar in the Custom Sidebar panel, type name and description and click Create Sidebar. I make a sidebar name Footer: Banner Ad

CS New Sidebar
2. Go to Widgets panel, see that the newly created sidebar name Footer: Banner Ad  is at the bottom of Sidebars
3. Drag and drop text widget to the Footer: Banner Ad sidebar, copy and paste your banner ad code

CS: Text Widget
4. Add following code to a theme file, e.g footer.php.

<?php if (function_exists('dynamic_sidebar')) { dynamic_sidebar('Footer: Banner Ad'); } ?>