WordPress.org

Forums

[resolved] How do I redirect to another page after a short delay (10 posts)

  1. wiresplus
    Member
    Posted 1 year ago #

    Hello,

    I want to have a thankyou page, that redirects after a short pause.

    The page id will be 432.

    I tried to add the following 7 second delay/redirect

    <?php if(is_page(432)){
    <meta http-equiv="refresh" content="7;url=[homepage url]" />
    }
    ?>

    in page.php, but no good.

    What should I be doing?

  2. wiresplus
    Member
    Posted 1 year ago #

    I tried this too, but this just breaks the page and I get a blank screen.

    <META HTTP-EQUIV="refresh" CONTENT="<?php if(is_page(432)){7;URL=http://kjscreations.co.nz/}?>">

  3. bcworkz
    Member
    Posted 1 year ago #

    page.php is only for content in <body> section, meta tags belong in <head> section, which is on headers.php and used for all pages, so something like your first effort makes more sense. However, is_page() is the wrong function. It only indicates if the post_type is 'page', not what page ID is being shown.

    To get the actual page ID, use the global $wp_query['queried_object_id']

  4. DYC - The Voice Of Generation
    Member
    Posted 1 year ago #

    you need to make changes in header.php file in your theme folder.

    i suggest you to use plugin for this task.. here are a lot of free plugin available on wordpress.org which can redirect to specified page after short delay of time.

  5. wiresplus
    Member
    Posted 1 year ago #

    @DYC I can't find a plugin that does it, maybe I don't know what to search for or something.

    @bcworkz - I'm not familiar with the $wp_query['queried_object_id'] bit

  6. wiresplus
    Member
    Posted 1 year ago #

    Here's header.php, down to head/>

    `<?php
    /**
    * The Header for our theme.
    *
    * Displays all of the <head> section and everything up till <div id="main">
    *
    * @package WordPress
    * @subpackage Twenty_Thirteen
    * @since Twenty Thirteen 1.0
    */
    ?><!DOCTYPE html>
    <!--[if IE 7]>
    <html class="ie ie7" <?php language_attributes(); ?>>
    <![endif]-->
    <!--[if IE 8]>
    <html class="ie ie8" <?php language_attributes(); ?>>
    <![endif]-->
    <!--[if !(IE 7) | !(IE 8) ]><!-->
    <html <?php language_attributes(); ?>>
    <!--<![endif]-->
    <head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width">
    <title><?php wp_title( '||', true, 'right' ); ?></title>
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
    <link rel="icon" type="image/png" href="favicon.png" />

    <!--[if lt IE 9]>
    <script src="<?php echo get_template_directory_uri(); ?>/js/html5.js"></script>
    <![endif]-->
    <?php wp_head(); ?>

    </head>`

    Sorry, but where should I put the $wp_Query?

  7. bcworkz
    Member
    Posted 1 year ago #

    I would put it right above <\head>. Something like this (untested):

    <?php global $wp_query;
    if( 432 == $wp_query['queried_object_id']){
       echo '<meta http-equiv="refresh" content="7;url=' . get_site_url() . '" />';
    }
    ?>
  8. wiresplus
    Member
    Posted 1 year ago #

    Thanks. It doesn't work. It simply returns an entirely white screen with no website :(

  9. wiresplus
    Member
    Posted 1 year ago #

    Hey hey!

    Fixed it: This is the code-

    <?php if(is_page( 432 )){ ?>
    <meta http-equiv="refresh" content="7;url=/?p=4" />
    <?php } ?>

    This nicely dumps the meta refresh into the page header if it is page 432.
    Answer cobbled from several sources, most useful was Stack Overflow

    Thanks to all!

  10. G4t0
    Member
    Posted 11 months ago #

    Thanks for share the code, just needed that function.
    Works great in WP 3.9.1

Topic Closed

This topic has been closed to new replies.

About this Topic