Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Add .html extension to product permalinks
- */
- function bis_detect_html_permalinks($query) {
- global $wpdb, $pm_query, $wp, $wp_rewrite;
- // Do not run if custom permalink was detected
- if(!empty($pm_query['id'])) {
- return $query;
- }
- if(!empty($query['product']) && strpos($query['product'], '.html') !== false) {
- $query['product'] = str_replace('.html', '', $query['product']);
- if(!empty($query['name'])) {
- $query['name'] = $query['product'];
- }
- // Disable canonical redirect
- remove_action('template_redirect', 'wp_old_slug_redirect');
- remove_action('template_redirect', 'redirect_canonical');
- add_filter('wpml_is_redirected', '__return_false', 99, 2);
- add_filter('pll_check_canonical_url', '__return_false', 99, 2);
- }
- return $query;
- }
- add_filter('request', 'bis_detect_html_permalinks', 9999);
- function bis_filter_product_permalinks($url, $element) {
- if(!empty($element->post_type) && ($element->post_type == 'product')) {
- $url .= ".html";
- }
- return $url;
- }
- add_filter('post_type_link', 'bis_filter_product_permalinks', 999, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement