Last active
February 9, 2018 22:49
-
-
Save amitramani/91ecffd4b2a8bba1d6f27db324442de9 to your computer and use it in GitHub Desktop.
How to get Crawler Based Search Engine for Swiftype on WordPress using Genesis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// October 11, 2015 Change search form text from https://wpbeaches.com/change-search-field-default-text-genesis-wordpress-theme/ | |
function themeprefix_search_button_text( $text ) { | |
return ( 'Start Typing...'); | |
} | |
add_filter( 'genesis_search_text', 'themeprefix_search_button_text' ); | |
function b3m_search_form( $form, $search_text, $button_text, $label ) { | |
$onfocus = " onfocus=\"if (this.value == '$search_text') {this.value = '';}\""; | |
$onblur = " onblur=\"if (this.value == '') {this.value = '$search_text';}\""; | |
$form = sprintf( | |
'<form method="get" class="searchform search-form" action="%s" role="search" >%s<input type="search" placeholder="%s" name="s" class="s search-input st-default-search-input" style="height: 50px;" autofocus="autofocus"/><button type="submit">Go</button></form>', | |
home_url( '/' ), | |
esc_html( $label ), | |
esc_attr( $search_text ) | |
); | |
return $form; | |
} | |
add_filter( 'genesis_search_form', 'b3m_search_form', 10, 4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sep 28, 2015 Add the Swiftype Meta Tag so the images show up in Search Results | |
* | |
*/ | |
function ar_add_swiftype_image_meta_tag($id = '0') | |
{ | |
global $post; | |
$post_id = $post->ID; | |
/* First, check if this post has a thumbnail */ | |
if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail( $post_id ) ) { | |
/* Get the full image path */ | |
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id )); | |
if ($thumb) { | |
/* Output the Swiftype Image Meta Tag */ | |
echo '<meta class="'.'swiftype"'.' name="'.'image"'.' data-type="'.'enum"'.' content="'.esc_attr($thumb[0]).'"/>'."\n"; | |
} | |
$price = get_post_meta( $post_id, '_regular_price', true); | |
//echo '<meta class="'.'swiftype"'.' name="'.'price"'.' data-type="'.'enum"'.' content="'.$price[0].'"/>'."\n"; | |
} | |
} | |
add_action('wpseo_opengraph', 'ar_add_swiftype_image_meta_tag', 40, $id); | |
/** | |
* Oct 20, 2015 Add the Swiftype Site Meta Tag so the results can be filtered by site/domain | |
* | |
*/ | |
function ar_add_swiftype_site_meta_tag($id = '0') | |
{ | |
/* Output the Swiftype Site Meta Tag */ | |
echo '<meta class="'.'swiftype"'.' name="'.'site"'.' data-type="'.'enum"'.' content="tacknrider"/>'."\n"; | |
} | |
add_action('wpseo_opengraph', 'ar_add_swiftype_site_meta_tag', 30, $id); | |
function swiftype_javascript_config() { | |
?> | |
<script type="text/javascript"> | |
var customRenderFunction = function(document_type, item) { | |
var title = item['highlight']['title'] || Swiftype.htmlEscape(item['title']); | |
var image = item['image']; | |
return '<p class="title"><img src="' + image + '" height="45" width="45">' + title + '</p>'; | |
}; | |
var swiftypeConfig = { | |
renderFunction: customRenderFunction | |
}; | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment