How can redirect the page after the header sent? Wordpress
<p>I made a plugin on wordpress. When the user click the view post button on the home page, It will check some condition to allow or not the user to view the post.</p>

<p>If the user isn't allowed to view the post, page will be redirected to the error page.</p>

<p>But, the problem is that, the plugin is ran by the shortcut, so the function will be ran after the post page loaded. And it come out this error <code>Cannot modify header information - headers already sent by (output started at /home/wordpress/wp-includes/class.wp-styles.php:237)</code></p>

<p>And how do the url redirect after the headers sent?</p>

<p>Also, I need to make it will the shortcut.</p>

<p>Thx a lot.</p>

<p>Here is my code:</p>

<pre><code>   function add_post_condition_vpc($atts, $content = null)
    {      

     $userPoint = getPointFromDb();
   if($userPoint &gt; 50)
                  {           

                     //redirect the the page to the view-post-direct-page.php
                     $page_file_temp = $_SERVER["PHP_SELF"];
                     $url= dirname($page_file_temp) . "/view-post-direct-page.php";
                     header("Location: $url ");
                     return "redirect";

                  }
  } 

  add_shortcode('view_post_lmc', 'add_post_condition_vpc');
</code></pre>

<p>And the share button, I used this code to get the current post url:</p>

<pre><code>$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
</code></pre>

<p>Then I add the shortcode on the post.</p>

<hr>

<p>I found a solution.</p>

<p>Here is my code:</p>

<pre><code>//redirect the the page to the view-post-direct-page.php
$page_file_temp = $_SERVER["PHP_SELF"];
$url= dirname($page_file_temp) . "/view-post-direct-page.php";

$string = '&lt;script type="text/javascript"&gt;';
$string .= 'window.location = "' . $url . '"';
$string .= '&lt;/script&gt;';

return $string;
</code></pre>

<p>Use <code>Javascript</code> to avoid send the <code>header again</code>. </p>