The MU forums have moved to WordPress.org

simple redirect to a theme php page (11 posts)

  1. bschwarting
    Member
    Posted 15 years ago #

    how can i redirect to my php pages in my themes? i tried this, but i get errors:

    <meta HTTP-EQUIV="refresh" content=0;url="../../wp-content/themes/default/testing.php">

  2. lunabyte
    Member
    Posted 15 years ago #

    Use Php's header function.

  3. ssbansal
    Member
    Posted 15 years ago #

    <?php
    $theme_location = "../../wp-content/themes/default/testing.php";

    header("Location: $theme_location");

    ?>

    Used the variable as it helps clean code up as i think so. Using a long url in a header() is very hard to understand.

  4. bschwarting
    Member
    Posted 15 years ago #

    ssbansal,

    ok, i put that and i get this error:

    Warning: Cannot modify header information - headers already sent by (output started at /homepages/38/htdocs/wp-content/themes/default/testing.php:7) in /homepages/38/htdocs/wp-content/themes/default/testing.php on line 21

    ideas?

  5. bschwarting
    Member
    Posted 15 years ago #

    nevermind, moved it to the top and it forwards, but i get the same thing as the HTTP-EQUIV="refresh"

    Fatal error: Call to undefined function get_header() in /homepages/38/htdocs/wp-content/themes/default/testing.php on line 1

  6. ssbansal
    Member
    Posted 15 years ago #

    get_header() is a function that isn't in any of the theme files. Either it hasn't been included or it has been called wrong.

    Look in the themes PHP files for:

    function get_header()

  7. bschwarting
    Member
    Posted 15 years ago #

    this was already in the top of the testing.php page

    <?php get_header(); ?>

    shouldn't this work?

  8. lunabyte
    Member
    Posted 15 years ago #

    get_header is a built-in WP template function.

    If you link directly to that file, no it won't run since WP hasn't been initialized.

    Instead, make testing.php a custom page template (see the codex), then create a page in wp-admin, use testing.php as the template, and then redirect to that pages permalink.

    "Warning: Cannot modify header information - headers already sent by (output started at "

    Put your header(Location call at the very top of the file redirecting, before the html output.

    The top of that file would look similar to:

    <?php
     if ( something ) {
       header...
    }
    ?>
    <DOCTYPE...
  9. bschwarting
    Member
    Posted 15 years ago #

    that makes sense. so if you ever want to link or redirect to a theme page "directly" that has WP functions, you have to do it through templates.

    that assumption correct?

  10. lunabyte
    Member
    Posted 15 years ago #

    That's the easiest way, yes.

    You can make custom pages, initialize WP yourself, etc. but it's easier for a single blog to do it that way.

    Make a page, use a custom template, do what you want in the template.

  11. bschwarting
    Member
    Posted 15 years ago #

    i like easy! thanks again :)

About this Topic

  • Started 15 years ago by bschwarting
  • Latest reply from bschwarting