document.addEventListener( 'DOMContentLoaded', function() { const searchToggleForms = document.querySelectorAll( '.is-style-toggle' ); [ ...searchToggleForms ].forEach( function( form ) { const button = form.getElementsByClassName( 'wp-block-search__button' )[ 0 ]; const input = form.getElementsByClassName( 'wp-block-search__input' )[ 0 ]; if ( ! input ) { return; } input.classList.add( 'is-hidden' ); button.remove(); form.parentNode.appendChild( button ); button.addEventListener( 'click', function() { input.classList.toggle( 'is-hidden' ); } ); } ); } );