Override a parent theme filter

Here is code frequently used to remove and replace a parent theme filter:

/*-----------------------------------------------------------------------------------*/
/* REMOVE & REPLACE A CUSTOM PARENT THEME FILTER */
/*-----------------------------------------------------------------------------------*/
// Setup the new function to replace the existing parent theme function
function pp_custom_password_form() {
	global $post;
	$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
	$o = '<div class="clearfix"><form class="protected-post-form" action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
	' . __( "<p>This post is password protected. To view it please enter your password below:</p>" ,'bonestheme') . '
	<label for="' . $label . '">' . __( "Password:" ,'bonestheme') . ' </label><div class="input"><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" class="btn btn-primary" value="' . esc_attr__( "Submit",'bonestheme' ) . '" /></div>
	</form></div>
	';
	return $o;
}

// In after_setup_theme remove the parent them filter & add the new function in a filter
add_action( 'after_setup_theme', 'pp_custom_password_form_setup' );
function pp_custom_password_form_setup() {
    remove_filter( 'the_password_form', 'custom_password_form' );
    add_filter( 'the_password_form', 'pp_custom_password_form' );
}

Revisions

Tags: , ,

No comments yet.

Leave a Reply