marjwyatt

Genesis - Modify Search for Adsense

Mar 18th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. // Replace genesis_search_form function for inclusion of adsense code
  2. // Change partner-pub numeric to agree with adsense account
  3. add_filter( 'get_search_form', 'custom_adsense_search_form' );
  4.  
  5. /*** Replace the default search form with a Adsense-specific form. **/
  6. function custom_adsense_search_form() {
  7.  
  8.     $search_text = get_search_query() ? esc_attr( apply_filters( 'the_search_query', get_search_query() ) ) : apply_filters( 'genesis_search_text', esc_attr__( 'Search this website', 'genesis' ) . '…' );
  9.  
  10.     $button_text = apply_filters( 'genesis_search_button_text', esc_attr__( 'Search', 'genesis' ) );
  11.  
  12.     $onfocus = " onfocus=\"if (this.value == '$search_text') {this.value = '';}\"";
  13.     $onblur  = " onblur=\"if (this.value == '') {this.value = '$search_text';}\"";
  14.  
  15.     /** Empty label, by default. Filterable. */
  16.     $label = apply_filters( 'genesis_search_form_label', '' );
  17.  
  18.     $form = '
  19.        <form method="get" class="searchform search-form" action="http://www.google.com.au/cse" id="cse-search-box" target="_blank" />
  20.             ' . $label . '
  21.            <input type="hidden" name="cx" value="partner-pub-0000000000000000:zghc4b-vsqt" />
  22.            <input type="hidden" name="ie" value="ISO-8859-1" />
  23.             <input type="text" value="' . esc_attr( $search_text ) . '" name="s" class="s search-input"' . $onfocus . $onblur . ' />
  24.             <input type="submit" name="sa" class="searchsubmit search-submit" value="' . esc_attr( $button_text ) . '" />
  25.         </form>
  26.        <script type="text/javascript" src="http://www.google.com.au/cse/brand?form=cse-search-box&amp;lang=en"></script>
  27.     ';
  28.  
  29.     return apply_filters( 'custom_adsense_search_form', $form, $search_text, $button_text, $label );
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment