Title: Code Entered Redirects To Post
Last modified: December 7, 2020

---

# Code Entered Redirects To Post

 *  [akimernest](https://wordpress.org/support/users/akimernest/)
 * (@akimernest)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/code-entered-redirects-to-post/)
 * Good Day Guys, is there any plugin or solution available that allows and generates
   codes such as ADJKSL etc… that when entered will redirect you to that specific
   article. I know this will be useful to many users.

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Moderator [tobifjellner (Tor-Bjorn “Tobi” Fjellner)](https://wordpress.org/support/users/tobifjellner/)
 * (@tobifjellner)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/code-entered-redirects-to-post/#post-13752681)
 * Do you mean some kind of URL shortener?
    See [https://wordpress.org/plugins/tags/url-shortener/](https://wordpress.org/plugins/tags/url-shortener/)
   for a starter
 *  Thread Starter [akimernest](https://wordpress.org/support/users/akimernest/)
 * (@akimernest)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/code-entered-redirects-to-post/#post-13754693)
 * Let’s say I wanted an entry form and the user enters the code and it takes them
   where they need to be.
    -  This reply was modified 5 years, 5 months ago by [akimernest](https://wordpress.org/support/users/akimernest/).
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/code-entered-redirects-to-post/#post-13755865)
 * What’s the reason for going through a code? I can more easily remember and type
   this topic’s slug `code-entered-redirects-to-post` than some random code string.
   Could you use the post’s ID as your “code”? The entry form’s processing script
   could then just append the ID to the site URL + `?p=`, then redirect to the resulting
   destination.
 *  Thread Starter [akimernest](https://wordpress.org/support/users/akimernest/)
 * (@akimernest)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/code-entered-redirects-to-post/#post-13755877)
 * So can guide me as to how I would that.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/code-entered-redirects-to-post/#post-13760631)
 * How depends on where the entry form submits to. Assuming it submits somewhere
   that initializes the WP environment, the form handler code might look something
   like:
 *     ```
       <?php
       wp_redirect( site_url('/?p=' . (int) $_REQUEST['code']));
       exit;
       ```
   
 * This assumes the form field in which one enters the post’s ID is named “code”.
   The redirect must occur before any response content is output.
 *  Thread Starter [akimernest](https://wordpress.org/support/users/akimernest/)
 * (@akimernest)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/code-entered-redirects-to-post/#post-13762031)
 * Right now I currently have nothing setup. If you know how to do it, that would
   be much appreciated.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/code-entered-redirects-to-post/#post-13766481)
 * On further thought, I would have my PHP form handler code avoid initiating the
   WP environment, contrary to what I said earlier. The PHP form handler code could
   send a `Location:` header to effect the redirect. You’ll need to hardcode the
   WP URL since `site_url()` will be unavailable (or get it from `$_SERVER`). Hardcoding
   means this would be unsuitable as a distributed plugin solution, but is more 
   efficient as a custom site specific solution. The PHP form handler file can reside
   anywhere on your server, it’s not part of WP.
 *     ```
       <?php
       header('Location: https://my-wp-site.com/?p=' . (int) $_REQUEST['code']);
       exit;
       ```
   
 * Assuming the above PHP is in /inc/my-redirect.php, your HTML form might look 
   like this:
 *     ```
       <form action="https://my-wp-site.com/inc/my-redirect.php">
         <label for="code">Page ID:</label>
         <input type="text" name="code" id="code">
         <input type="submit" value="Go">
       </form>
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Code Entered Redirects To Post’ is closed to new replies.

## Tags

 * [development](https://wordpress.org/support/topic-tag/development/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 7 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [5 years, 5 months ago](https://wordpress.org/support/topic/code-entered-redirects-to-post/#post-13766481)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
