They usually run on the the_content
hook which is well after content is sent to the browser. If you need to redirect based on the presence of a short code you need to check for that short code before any content leaves the server.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function pre_process_shortcode() { if (!is_singular()) return; global $post; if (!empty($post->post_content)) { $regex = get_shortcode_regex(); preg_match_all('/'.$regex.'/',$post->post_content,$matches); if (!empty($matches[2]) && in_array('yourshortcodeslug',$matches[2]) && is_user_logged_in()) { // redirect to third party site } else { // login form or redirect to login page } } } add_action('template_redirect','pre_process_shortcode',1); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.