Support » Plugins » Redirect after Publishing Post

  • Resolved Aeriff


    Hi there, I am developing a plugin to redirect to an external page after publishing my post. I have read about Hooks and Actions and have come up with the following code:

    add_action('post_publish', 'redirect', 0);
    function redirect($nothing) {
    	$permalink = get_permalink($_GET["posted"]);
    	$location = "$permalink";

    WordPress isn’t even detecting the plugin even though it’s activated, it’s still redirecting to the usual New Post page with the box saying the post has been published. The $_GET[“posted”] is for getting the post ID from the post-new.php?posted=ID page (if that will work?). I’d appreciate any ideas on how to get the post ID and then the permalink also by using this plugin, or if someone could point me in the right diretions. Someone even fixing my code so that it will work and reposting it would be greatly appreciated as this is my first plugin.


Viewing 2 replies - 1 through 2 (of 2 total)
  • Have you found an answer to this question?

    I solved this problem! There were a couple of things wrong with your code. Here’s the code that worked for me.


    function redirect($post_id) {
    $permalink = get_permalink($post_id);
    $location = “”.$permalink;

    1 – The action is publish_post (not post_publish)
    2 – Pass $post_id to the redirect function instead of $nothing
    3 – Run get_permalink on $post_id instead of ($_GET[“posted”])
    4 – You concatenated $permalink to the $location improperly. See the difference in the way I did it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect after Publishing Post’ is closed to new replies.