Title: Action hook before redirection plugin
Last modified: December 7, 2017

---

# Action hook before redirection plugin

 *  [pasaro333](https://wordpress.org/support/users/pasaro333/)
 * (@pasaro333)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/action-hook-before-redirection-plugin/)
 * I have many old blogger permalinks that still cached on google and others directories.
   To redirect them to the correct posts I tried to use this function in my theme
   function.php.
 *     ```
       add_action('wp-head', 'wp_redirect_blogger_oldlink');
       function wp_redirect_blogger_oldlink() {
       $Rurl = $_SERVER['REQUEST_URI'];
       if (stripos($Rurl,'html') !== false) {
       $res = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_permalink'");
       if ($res) {
       $Aurl= strstr($SERVER[REQUEST_URI], '', true);
       $Burl = strstr($_SERVER[REQUEST_URI], '.html', true);
       foreach ($res as $row) {
       if ( stripos($row->meta_value, $Burl) !== false || stripos($row->meta_value, $Aurl) !== false ) {
       wp_redirect( get_permalink($row->post_id), 301 );
       die();
       }}}}}
       ```
   
 * _[Moderator note: code fixed. Please wrap code in the backtick character or [use the code button](https://make.wordpress.org/support/handbook/forum-welcome/#post-code-safely).]_
 * The function failed to work in my theme function.php but can works well when 
   I put it in the 404.php, which is in redirection plugin log report counts as 
   404 reports.
 * It seems like I have to use a right action hook to trigger the function “BEFORE”
   the redirection plugin in the theme function.php.
 * Any ideas how to solve this problem?
 * Thanks in advance.
    -  This topic was modified 8 years, 6 months ago by [bdbrown](https://wordpress.org/support/users/bdbrown/).

The topic ‘Action hook before redirection plugin’ is closed to new replies.

 * ![](https://ps.w.org/redirection/assets/icon-256x256.jpg?rev=983639)
 * [Redirection](https://wordpress.org/plugins/redirection/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/redirection/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/redirection/)
 * [Active Topics](https://wordpress.org/support/plugin/redirection/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/redirection/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/redirection/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [pasaro333](https://wordpress.org/support/users/pasaro333/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/action-hook-before-redirection-plugin/)
 * Status: not resolved