Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter MrAnt

    (@mant)

    Hi Albert,

    Thanks for the response. It looks like you have replaced my (.*) with ([a-z]+) which are very similar. The + would be 1 or more characters, compared to the asterisk I used which is 0 or more. The . in my case included any characters apart from line breaks, whereas [a-z] limits to lower case letters.

    I was trying to address urls like https://caloriestar.com/gb/?s=chocolate so the [a-z]+ would not match as there is only the trailing slash before the query parameters.

    In the end as the rewrite rules were working fine apart from the search I used the nginx rewrite functionality to resolve.

            location ~ "/(?<cn>[a-z]{2})/?$" {
                    if ($arg_s != "") {
                            return 301 /$cn/search/$arg_s;
                    }
                    try_files $cn/$uri /index.php?$args&countrycn=$cn;
            }

    Although I used the following code to change the Search URL, this did not seem to be picked up everywhere, so I write a shortcode that would output the correct code based on country selected.

    function change_search_url_rewrite() {
    	if ( is_search() && ! empty( $_GET['s'] ) ) {
    		$country = get_query_var('cscountry');
    
    		if ($country <> '') {
    			$country = '/'.$country;
    		}
    
    		wp_redirect( home_url( $country."/search/" ) . urlencode( get_query_var( 's' ) ) );
    		exit();
    	}
    }
    add_action( 'template_redirect', 'change_search_url_rewrite' );
    

    Putting this here in case it comes in useful to others in the future.

    • This reply was modified 2 years, 9 months ago by MrAnt. Reason: Edited to mark as resolved
    MrAnt

    (@mant)

    Hi,

    I was finding the same problem. Took a while to diagnose as sometimes JQuery loads up quick enough and the problem is avoided, but occasionally this does not happen and JavaScript stops processing with the same error you described. Most often was happening on this page for me, but not every time, around 1 in 10.

    Found the problem was not Cookie Consent and that jQuery was loaded with defer/async. Have removed that problem and now site working fine again, with latest versions of Cookie Consent and AutoOptimise.

    Found the cause in my theme functions, but could be a plugin, etc. Check the source of the page to see if jQuery has a Defer/Async and find the cause of this to see if it is the same problem as mine.

    Anthony

    Ant

Viewing 2 replies - 1 through 2 (of 2 total)