Archive | July 2012

Force custom post type to be private

function force_type_private($post)
    if ($post['post_type'] == 'my_post_type')
    $post['post_status'] = 'private';
    return $post;
add_filter('wp_insert_post_data', 'force_type_private');

How to remove “private” and “protected” from the post title

function the_title_trim($title) {
	$title = attribute_escape($title);
	$findthese = array(
	$replacewith = array(
		'', // What to replace "Protected:" with
		'' // What to replace "Private:" with
	$title = preg_replace($findthese, $replacewith, $title);
	return $title;
add_filter('the_title', 'the_title_trim');

Clear Input Field on Focus

Use this code to style your input field with simple function

<input type="text" name="email" onfocus="if(this.value == 'email address') { this.value = ''; }" value="email address" onblur="if(this.value==''){this.value = 'email address';}" />

Replace “email address” with your own text.

WordPress: Adding a class to first and last menu items

function add_first_and_last($output) {
$output = preg_replace('/class="menu-item/', 'class="first-menu-item menu-item', $output, 1);
$output = substr_replace($output, 'class="last-menu-item menu-item', strripos($output, 'class="menu-item'), strlen('class="menu-item')); return $output;
add_filter('wp_nav_menu', 'add_first_and_last');