0

In some part of our customizer we are redirecting users to some specific pages.

var url = 'https://test.com/specific-page'; 
api.previewer.previewUrl.set( url );

We want to pass a custom query along with URL but it's not working as expected. We tried following codes.

Code 1: (not working at all)

_.extend( api.previewer.query, { custom_query: 123 } )
api.previewer.previewUrl.set( getFrontendPreviewUrl() );

Code 2: (it works but after several reloads, it adds several ? to url)

api.previewer.previewUrl.set( api.previewer.previewUrl()  + '?custom_query=' + 123);
0

How about checking if the preview URL already contains your custom_query before adding it?

Something like:

var currentURL = api.previewer.previewUrl();

if (strpos(currentURL, 'custom_query') === false) {
    // do something
} else {
    // do something else
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.