arie_cristianD

replicate jnews search form header as shortcode

Sep 7th, 2025
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. /**
  2.  * Shortcode: [juice_search_form class="additional-classname"]
  3.  */
  4. function juice_custom_search_form( $atts = array(), $content = '' ) {
  5.     $atts        = shortcode_atts(
  6.         array(
  7.             'class' => '',
  8.         ),
  9.         $atts,
  10.         'juice_search_form'
  11.     );
  12.     $extra_class = trim( preg_replace( '/[^A-Za-z0-9_\-\s]/', '', $atts['class'] ) );
  13.  
  14.     $wrapper_classes = trim(
  15.         sprintf(
  16.             'jeg_search_wrapper jeg_search_no_expand %s %s',
  17.             get_theme_mod( 'jnews_header_menu_search_form_style', 'round' ),
  18.             $extra_class
  19.         )
  20.     );
  21.  
  22.     ob_start();
  23.     ?>
  24.     <div class="jeg_nav_item jeg_nav_search">
  25.         <div class="<?php echo esc_attr( $wrapper_classes ); ?>">
  26.             <a href="#" class="jeg_search_toggle" aria-label="<?php esc_attr_e( 'Toggle search', 'jnews' ); ?>">
  27.                 <i class="fa fa-search" aria-hidden="true"></i>
  28.             </a>
  29.             <?php
  30.             get_search_form();
  31.             ?>
  32.         </div>
  33.     </div>
  34.     <?php
  35.     return ob_get_clean();
  36. }
  37. add_shortcode( 'juice_search_form', 'juice_custom_search_form' );
Advertisement
Add Comment
Please, Sign In to add comment