I would like to redirect the index.php
to another file in my theme directory, but I get an error. about.php
exists in the theme root directory, but it's not a page template, so there is no reference to it in the database.
index.php
<?php
wp_redirect(get_site_url()."/about.php");
exit;
?>
Error
This page isn’t working
localhost redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS
What am I doing wrong?
CodePudding user response:
You can use this script for redirect to specific standalone test.php page of theme root directory. you need to use get_stylesheet_directory_uri() function because your PHP page exists in theme ROOT directory.
wp_redirect( get_stylesheet_directory_uri()."/test.php" ); exit;
CodePudding user response:
I have found a solution using these guides:
- https://developer.wordpress.org/themes/template-files-section/page-template-files/
- https://wordpress.stackexchange.com/questions/271878/how-to-properly-insert-a-link-to-a-template-in-wordpress
For anyone, who faces the same problem, just follow these steps:
- Create a single use page template with the
page-
prefix in the theme root directory. (e.g.page-about.php
)- If you put
<?php /* Template Name: About */ ?>
to the top of the template file, it will be available for editors on the "New Page" interface as a page type. If you want to avoid that, just don't use this line.
- If you put
- On the "New Page" interface, create a new page with the slug you prefixed with
page-
in the file name. (e.g.about
) - After these steps, Wordpress will know to load your template file, if you link it using the page's slug.
- You can use the
site_url()
function to create a link. (e.g.<a href="<?php echo site_url("about"); ?>">About</a>
) - Or you can use the
wp_redirect()
function to send the user to the desired page. (e.g.wp_redirect("about"); exit;
)
- You can use the