Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Search form support for AMP
// Search Form
function ampforwp_get_search_form() {
$form = '<form role="search" method="get" id="searchform" class="searchform" target="_top" action="' . trailingslashit( get_bloginfo('url') ) . '?' . AMP_QUERY_VAR . '">
<div>
<label class="screen-reader-text" for="s">' . _x( 'AMP SEARCH:', 'label' ) . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
</div>
</form>';
return $form;
}
function ampforwp_the_search_form() {
echo ampforwp_get_search_form();
}
function advanced_search_query($query) {
$ampforwp_is_amp_endpoint = ampforwp_is_amp_endpoint();
if ( ! $ampforwp_is_amp_endpoint ) {
return $query;
}
if($query->is_search() ) {
$query->set( 'amp', '1' );
}
}
function addfdsfsfbnsdfkhf() {
add_action('pre_get_posts', 'advanced_search_query', 1000);
}
add_action('pre_amp_render_post','addfdsfsfbnsdfkhf');
@MohammedKaludi
Copy link
Author

MohammedKaludi commented Jan 18, 2017

To use the form

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment