Title: Change URI query string while processing shortcode
Last modified: February 15, 2021

---

# Change URI query string while processing shortcode

 *  [flymike](https://wordpress.org/support/users/flymike/)
 * (@flymike)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/change-uri-query-string-while-processing-shortcode/)
 * During processing of a shortcode, my plugin reacts to a URI query string
 * > ?action=1
 * , changes some state in the database, and includes a status message in the content
   returned by the shortcode.
 * When the page is eventually rendered, the browser’s Location bar still contains
   that query string, as part of the URI.
 * If the user then refreshes the page, my shortcode processing will again process
   the query string but now see that the state has already been changed, so include
   a warning message in the content by the shortcode.
 * The warning is confusing to the user, so I’m looking for a way to remove that
   query string, after it has first been processed.
 * I considered including some javascript which would remove the query string from
   the URI and reload the page. But the user would then never see the status message
   included when the query string was originally processed.
 * Any ideas on removing the query string after it’s been processed?
    -  This topic was modified 5 years, 1 month ago by [flymike](https://wordpress.org/support/users/flymike/).

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

 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/change-uri-query-string-while-processing-shortcode/#post-14054595)
 * A little bit of googling and I found
 *     ```
       if (history.pushState) {
           var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname;
           window.history.pushState({path:newurl},'',newurl);
       }
       ```
   
 * Untested
 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/change-uri-query-string-while-processing-shortcode/#post-14054603)
 * And
 * `history.replaceState(null, "", location.href.split("?")[0]);`
 * Untested
 *  Thread Starter [flymike](https://wordpress.org/support/users/flymike/)
 * (@flymike)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/change-uri-query-string-while-processing-shortcode/#post-14054865)
 * Thanks. I realize I can reload the page without the query string using JS but,
   if I do that, the user will never get chance to see the status message which 
   I present on the original page.
 * To clarify, I present a **status** message when the state is changed, but a **
   warning** message if the user subsequently attempts to change the state again.
 * Maybe one solutions is a 5 second delay before the JS reloads the page, so that
   the user can briefly see the status message. But that seems a bit of a hack…
 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/change-uri-query-string-while-processing-shortcode/#post-14054883)
 * Both solutions remove the query string without reloading the page, apparently.
 *  Thread Starter [flymike](https://wordpress.org/support/users/flymike/)
 * (@flymike)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/change-uri-query-string-while-processing-shortcode/#post-14054894)
 * My apologies. I missed that point completely. I’ll research [that](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState).
 * Thanks again.
 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/change-uri-query-string-while-processing-shortcode/#post-14054900)
 * That is OK, the search term I used was
 * > modify query string without reloading page

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

The topic ‘Change URI query string while processing shortcode’ is closed to new 
replies.

## Tags

 * [Query String](https://wordpress.org/support/topic-tag/query-string/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 6 replies
 * 2 participants
 * Last reply from: [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/change-uri-query-string-while-processing-shortcode/#post-14054900)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
