Skip to content

Snippets / HTML

HTML

Create Post (VX) - Redirect after Submission

S Steven Ellis · 93 views · Updated 5 months ago
I used Gemini AI to help me with this little snippet.
If anyone finds fault in this code, please please let me know. But for me, it works!
The setup:- User creates a post- In my case, the post is set to 'Pending Review'- The redirect url to the post created is the edit post url structure.
I'm sure there's a more elegant way, but this works for me.
NOTE: I was using the Essential Add-ons for Voxel, but have found this plugin extremely buggy and unreliable.
Thanks.
Give your Create Post (VX) widget an ID name. In my example it is 'create-location'. Add the code below in an HTML code widget below the Create Post (VX) widget. Change: const finalUrl = `${baseUrl}/?post_type=YOUR_POST_TYPE_HERE&p=${newPostId}`;
<script>
(function() {
const targetNode = document.getElementById('create-location');
if (!targetNode) return;

const config = { childList: true, subtree: true };

const callback = function(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
// Detecting the Voxel success message
if (targetNode.innerText.includes("Your post has been submitted for review")) {

const links = targetNode.querySelectorAll('a');
let newPostId = null;

// Extracting the ID from the "Back to editing" button link
links.forEach(link => {
const href = link.getAttribute('href');
const match = href.match(/(?:post_id=|posts\/)(\d+)/);
if (match && match[1]) {
newPostId = match[1];
}
});

observer.disconnect();

if (newPostId) {
// Uses the current domain automatically
const baseUrl = window.location.origin;
const finalUrl = `${baseUrl}/?post_type=location-directory&p=${newPostId}`;

window.location.href = finalUrl;
} else {
// Fallback to the current page/home if ID is missed
window.location.href = '/';
}
}
}
}
};

const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
})();
</script>
HTML · 46 lines

Discussion

Ask a question or share how you used this.

Log in to join the discussion.

No comments yet — be the first.

Voxel Guide assistant
Ask about snippets, addons & how-tos

Hey — how can I help?

I can dig through the library for snippets, addons, and tutorials.

AI can be wrong — double-check anything important.