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 Conditional Tag for Login Page

WordPress have conditional tags. The Conditional Tags can be used in your Template files to change what content is displayed and how that content is displayed on a particular page depending on what conditions that page matches

Following conditional tag is specific to Login Page, that is currently not available on WordPress Codex

if ( in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) {
//Conditional statement here

Keep HTML Tags in WordPress Limit Posts – the_content_limit

WordPress - the logoThis function, the_content_limit  controls the maximum amount of characters displayed for an entry on the main page on WordPress homepage posts, e.g Featured Posts, Recent Posts
However , the_content_limit stripped HTML tags just like the_excerpt. What if we want to keep HTML tags

We make modification to the function, the_content_limit which is usually found in functions.php

function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
// remove  shortcode
$content = preg_replace("/\/", '', $content);
// short codes are applied

$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content,'

if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
echo "
echo $content;
echo "...";
echo "

else {
echo "
echo $content;
echo "


We remove $content = strip_tags($content);  from original code of the_content_limit and replace it with $content = strip_tags($content,'<p>,<b>,<strong>,<a>,<i>,<br>’);
This will allow the_content_limit to show paragraph, bold texts, italic texts.

What is strip_tags?

We can remove all html tags from the content by using strip_tags string function in PHP. This function can be used to collect only the content part without reading the html formatting of the page. Here is the syntax

strip_tags (input string [, string allowable_tags])

This function also allows one optional string where we can keep the tags which are not to be removed. Say we don’t want the hyper links to be removed. So we will allow the linking tag <a href to be kept as it is. Here is the syntax for this.

strip_tags($string_str, ‘<a>’);

In the above code $string_str is the input string, in our case it is $content