Beautify URL
-
Hi guys! Is there any chance to beautify the URL returned from YMM selector? I mean to make it shorter and more readable?
Many thanks!
-
Hello,
It is possible to make the search results page work with a SEO URL like:
https://website.com/vehicle/BMW/X3/2008/instead of:
https://website.com/?s=&ymm_search=1&post_type=product&_make=BMW&_model=X3&_year=2008Contact me by email [email protected] I will send the modified files to you.
Stanislav
Hello,
If someone else also needs it.
Add the code:
add_action('init', '_ymm_add_url_parameters'); add_filter('query_vars', '_ymm_add_query_vars'); add_action('parse_query', '_ymm_parse_query'); function _ymm_add_url_parameters(){ // To make it work with SEO URL like: // https://website.com/vehicle/BMW/X3/2008/ // instead of: // https://website.com/?s=&ymm_search=1&post_type=product&_make=BMW&_model=X3&_year=2008 // // Don't forget to refresh the wordpress permalink settings after changing the rewrite rules in: // WordPress dashboard -> Settings -> Permalink // click the "Save changes" button at the bottom of the page add_rewrite_rule('^vehicle/([A-Za-z0-9-\s]+)/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]', 'top'); add_rewrite_rule('^vehicle/([A-Za-z0-9-\s]+)/page/([0-9]{1,})/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]&paged=$matches[2]', 'top'); add_rewrite_rule('^vehicle/([A-Za-z0-9-\s]+)/([A-Za-z0-9-\s]+)/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]&_model=$matches[2]', 'top'); add_rewrite_rule('^vehicle/([A-Za-z0-9-\s]+)/([A-Za-z0-9-\s]+)/page/([0-9]{1,})/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]&_model=$matches[2]&paged=$matches[3]', 'top'); add_rewrite_rule('^vehicle/([A-Za-z0-9-\s]+)/([A-Za-z0-9-\s]+)/([0-9]+)/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]&_model=$matches[2]&_year=$matches[3]', 'top'); add_rewrite_rule('^vehicle/([A-Za-z0-9-\s]+)/([A-Za-z0-9-\s]+)/([0-9]+)/page/([0-9]{1,})/?$', 'index.php?s=&ymm_search=1&post_type=product&_make=$matches[1]&_model=$matches[2]&_year=$matches[3]&paged=$matches[4]', 'top'); } function _ymm_add_query_vars($aVars) { $aVars[] = "ymm_search"; $aVars[] = "_make"; $aVars[] = "_model"; $aVars[] = "_year"; return $aVars; } function _ymm_parse_query($where) { $ymm_make = get_query_var('_make'); if ($ymm_make){ $_GET['ymm_search'] = get_query_var('ymm_search'); $_GET['_make'] = get_query_var('_make'); $_GET['_model'] = get_query_var('_model'); $_GET['_year'] = get_query_var('_year'); $_GET['s'] = get_query_var('s'); } }to the end the file:
wp-content/plugins/ymm-search/ymm-search.phpReplace the line:
window.location.href = url + '?' + $.param(params);with:
if (!categoryUrl){ var pNames = this.levelParameterNames; var l = pNames.length; url = url.replace(/\/+$/, ''); url += '/vehicle/'; for (var i=0;i<l;i++) { if (values[pNames[i]] != undefined){ url += values[pNames[i]] + '/'; } } window.location.href = url; // seo url www.website.com/vehicle/BMW/X5/2000/ } else { window.location.href = url + '?' + $.param(params); }in the file:
wp-content/plugins/ymm-search/view/frontend/web/main.jsAfter applying the modification refresh the wordpress permalink settings in:
Wordpress dashboard -> Settings -> Permalink
click the “Save changes” button at the bottom of the page.And refresh your browser cache to make it load the updated version of the .js file.
Stanislav
The topic ‘Beautify URL’ is closed to new replies.