Title: Redirect with a shortcode
Last modified: August 31, 2016

---

# Redirect with a shortcode

 *  [MrFent37](https://wordpress.org/support/users/mrfent37/)
 * (@mrfent37)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/redirect-with-a-shortcode/)
 * Hello, I was wondering if it would be possible to add the ability to add a custom
   shortcode to the redirect field. For example, my client has a weekly radio show
   that I want to post a link to the schedule of when she is on (every tuesday) 
   and the url for each day is always changing, so I’ve created this shortcode:
 * add_shortcode( ‘radioschedule’, ‘radioschedule’ );
    function radioschedule() {
   $radioschedule = sprintf(‘[http://www.hayhouseradio.com/#!/schedule-by-day/%s&#8217](http://www.hayhouseradio.com/#!/schedule-by-day/%s&#8217);,
   date(“Y-m-d”, strtotime(“this Tuesday”))); return $radioschedule; }
 * So no matter what day it is, it always returns the url of the upcoming tuesday
   date. It would be really nice to be able to simply add the shortcode [radioschedule]
   in the redirect field, so that the redirect url will always be dynamic. Thanks!
 * [https://wordpress.org/plugins/quick-pagepost-redirect-plugin/](https://wordpress.org/plugins/quick-pagepost-redirect-plugin/)

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

 *  [Don Fischer](https://wordpress.org/support/users/prophecy2040/)
 * (@prophecy2040)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/redirect-with-a-shortcode/#post-7056009)
 * MrFent37,
    The plugin cannot do that, unfortunately. That said, since you are
   proficient enough to create a shortcode, I will tell you how I would go about
   doing something like this (if it were me).
    - Create a page called **‘Weekly Schedule’** or something similar.
    - Add a **custom field** to that page, say ‘`schedule-url`‘ and have the value
      be the URL pattern you want to use – in this case, something like ‘`http://
      www.hayhouseradio.com/#!/schedule-by-day/[schedule-url]`‘.
    - In the `functions.php` file (where you would have added your shortcode) add
      the following (after the `<?php`):
    -     ```
          add_action('template_redirect', 'override_schedule_link_custom', 5);
          function override_schedule_link_custom(){
          	global $post;
          	if( is_admin() || is_404() || !is_singular() || !isset( $post->ID ) )
          		return;
          	$link = get_post_meta( $post->ID, 'schedule-url', true );
          	if( $link != '' ){
          		$redirect_link = str_replace( '[schedule-url]' , date( "Y-m-d", strtotime( "this Tuesday" ) ) , $link );
          		wp_redirect( $redirect_link, 302 );
          		exit;
          	}
          }
          ```
      
    - This will redirect if the post has the custom field called `schedule-url` (
      does not matter the page or the post, as long as it has that custom field).
 * Then when anyone goes to `http://yoursitehere.com/weekly-schedule/`, they will
   always get redirected to the that same URL you posted in your page. You could
   put the link in any page or anywhere on the web and it will work. You could even
   throw this code in a plugin and use it that way too.
 * > **Disclaimer ** – I typed this off the top of my head, on-the-fly, so there
   > could be errors – but is should point you in the correct direction if it does
   > not work out of the box.
 * Best of luck,
    Don
 *  Thread Starter [MrFent37](https://wordpress.org/support/users/mrfent37/)
 * (@mrfent37)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/redirect-with-a-shortcode/#post-7056032)
 * Thanks Don! I decided to just go with a custom wp_redirect(); function instead
 *  [zdavis](https://wordpress.org/support/users/zdavis/)
 * (@zdavis)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/redirect-with-a-shortcode/#post-7056285)
 * Hello MrFent37,
 * Could you post your code of how you accomplished this? I’m also looking to put
   shortcode into the url.
 * Thanks!
 *  Thread Starter [MrFent37](https://wordpress.org/support/users/mrfent37/)
 * (@mrfent37)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/redirect-with-a-shortcode/#post-7056286)
 * zdavis, I didn’t actually use my shortcode, nor did I even use this plugin to
   accomplish what I needed to do. I just created a custom redirect function, and
   applied it to the one specific page that I needed to dynamically redirect to.
   Here’s my code:
 *     ```
       function hayhouse_radio_page() {
        $hayhouseradio = sprintf('http://www.hayhouseradio.com/#!/schedule-by-day/%s', date("Y-m-d", strtotime("this Tuesday")));
        if (is_page(57476)) {
           wp_redirect($hayhouseradio);
           exit;
        }
       }
       add_action('template_redirect','hayhouse_radio_page');
       ```
   

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

The topic ‘Redirect with a shortcode’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/quick-pagepost-redirect-plugin_8d7b6f.
   svg)
 * [Quick Page/Post Redirect Plugin](https://wordpress.org/plugins/quick-pagepost-redirect-plugin/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/quick-pagepost-redirect-plugin/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/quick-pagepost-redirect-plugin/)
 * [Active Topics](https://wordpress.org/support/plugin/quick-pagepost-redirect-plugin/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/quick-pagepost-redirect-plugin/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/quick-pagepost-redirect-plugin/reviews/)

## Tags

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

 * 4 replies
 * 3 participants
 * Last reply from: [MrFent37](https://wordpress.org/support/users/mrfent37/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/redirect-with-a-shortcode/#post-7056286)
 * Status: not resolved