Skip to content

Instantly share code, notes, and snippets.

@WPDevHQ
Last active February 20, 2017 07:54
Show Gist options
  • Save WPDevHQ/6d9fd8f0a6689f7c749caf3895e7c467 to your computer and use it in GitHub Desktop.
Save WPDevHQ/6d9fd8f0a6689f7c749caf3895e7c467 to your computer and use it in GitHub Desktop.
wp-localize-script.txt
// In the case of a theme this goes in functions.php and for plugins I use plugin.php :)
function frontend_assets(){
// Enqueue your assets here and add your localization like so!
wp_localize_script( $this->ssp_plugin_slug, 'ss_panel', array(
'success' => __( 'Here are your search results!', 'textdomain' ),
'failure' => __( 'Sorry, no results matched your search query. Try searching again?', 'textdomain' ),
));
}
add_action( 'wp_enqueue_scripts', 'frontend_assets' );
// This goes in your JS file i.e custom.js
$('#ss-panel-search-form form').bind('submit',function(){
$.get(
// Some Code has been reducted but here are the translatable strings from the above function
function(results){
// set to global variable so load more function can access
ss_panel.search_results = results;
//show message to user either way
var messages = {
'success': ss_panel.success,
'failure': ss_panel.failure
};
}
// More code reducted!
);
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment