Revision 246 is a pre-publication revision. (Viewing current revision instead.)

Override a parent theme filter

Here is code frequently used to remove and replace a parent theme filter: [php]/*-----------------------------------------------------------------------------------*/ /* 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' ); } [/php]

Revisions

  • August 6, 2012 @ 12:48:19 [Current Revision] by PeterLugg
  • August 6, 2012 @ 12:44:32 by PeterLugg

Revision Differences

August 6, 2012 @ 12:44:32Current Revision
Content
 Added: Here is code frequently used to remove and replace a parent theme filter:
 Added: [php]/*------ ------------- ------------ ------------- ------------ ------------- --------------*/
 Added: /* REMOVE &amp; REPLACE A CUSTOM PARENT THEME FILTER */
 Added: /*----------- ------------- ------------ ------------- ------------ ----------------------*/
 Added: // Setup the new function to replace the existing parent theme function
 Added: function pp_custom_password_form() {
 Added: global $post;
 Added: $label = 'pwbox-'.( empty( $post-&gt;ID ) ? rand() : $post-&gt;ID );
 Added: $o = '&lt;div class=&quot;clearfix&quot; &gt;&lt;form class=&quot;protected- post-form&quot; action=&quot;' . get_option('siteurl') . '/wp-login.php?action= postpass&quot; method=&quot; post&quot;&gt;
 Added: ' . __( &quot;&lt;p&gt;This post is password protected. To view it please enter your password below:&lt;/p&gt;&quot; ,'bonestheme') . '
 Added: &lt;label for=&quot;' . $label . '&quot;&gt;' . __( &quot;Password:&quot; ,'bonestheme') . ' &lt;/label&gt;&lt;div class=&quot;input&quot; &gt;&lt;input name=&quot;post_ password&quot; id=&quot;' . $label . '&quot; type=&quot;password&quot; size=&quot;20&quot; /&gt;&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; class=&quot;btn btn-primary&quot; value=&quot;' . esc_attr__( &quot;Submit&quot; ,'bonestheme' ) . '&quot; /&gt;&lt;/div&gt;
 Added: &lt;/form&gt; &lt;/div&gt;
 Added: ';
 Added: return $o;
 Added: }
 Added: // In after_setup_theme remove the parent them filter &amp; add the new function in a filter
 Added: add_action( 'after_setup_theme', 'pp_custom_password_form_setup' );
 Added: function pp_custom_password_ form_setup() {
 Added: remove_filter( 'the_password_form', 'custom_password_form' );
 Added: add_filter( 'the_password_form', 'pp_custom_password_form' );
Deleted: Added: }
 Added: [/php]

Note: Spaces may be added to comparison text to allow better line wrapping.

Tags: , ,

No comments yet.

Leave a Reply