WordPress: How to Hide Custom Field Meta Key from Custom Fields panel

WordPress - the logo
I learned this trick when someone asked about How to Hide Custom Fields Meta Key from Custom Fields panel. This trick useful when you want to hide certain Custom Fields Meta Key and Value from client or authors
Custom Fields
Add following code to functions.php

add_filter('is_protected_meta', 'my_is_protected_meta_filter1', 10, 2);
function my_is_protected_meta_filter1($protected, $meta_key) {
    return $meta_key == 'mymetakey_no1' ? true : $protected;
}

This code to hide a Custom Field Meta Key, just change mymetakey_no1 to meta key name that you wanted to hide. What if you want to hide two Meta Key?, add following to functions.php underneath above code
[/php]
add_filter(‘is_protected_meta’, ‘my_is_protected_meta_filter2’, 10, 2);
function my_is_protected_meta_filter2($protected, $meta_key) {
return $meta_key == ‘mymetakey_no2’ ? true : $protected;
}
[/php]

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 . ' />';

to

/* 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

wpdatetimesettings
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
Date

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

Time

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