Skip to content

Instantly share code, notes, and snippets.

@mizrael
Last active July 15, 2016 15:17
Show Gist options
  • Save mizrael/68368f510b82722d8028ee3efd01d67d to your computer and use it in GitHub Desktop.
Save mizrael/68368f510b82722d8028ee3efd01d67d to your computer and use it in GitHub Desktop.
Wordpress: how to handle redirects in shortcode
class my_shortcode{
public function __construct()
{
add_shortcode('my_shortcode', array($this, 'render_form'));
add_action( 'template_redirect', array($this, 'handle_form_post') );
}
function render_form(){
// guess what goes there :D
}
function handle_form_post(){
if ( isset( $_POST[''my_shortcode_form_name'] ) ) {
$dest_url = 'set your url';
wp_redirect($dest_url);
exit;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment