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?
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;
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.
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. About)
Or you can use the wp_redirect() function to send the user to the desired page. (e.g. wp_redirect("about"); exit;)
Related
I was editing my WordPress dashboard and I made a type in the site url.
This typo is now causing me to be redirected to a nonexistent domain whenever I try to login through the dashboard.
how can I fix this? I currently have FTP access.
I think the issue is you have entered the wrong domain name in the site URL and home URL.
that's why you are not able to access the website.
For this issue, there are two ways.
1) the First Method
Edit wp-config.php
It is possible to set the site URL manually in the wp-config.php file.
Add these two lines to your wp-config.php, where “example.com” is the correct location of your site.
define( 'WP_HOME', 'http://example.com' );
define( 'WP_SITEURL', 'http://example.com' );
This is not necessarily the best fix, it’s just hard-coding the values into the site itself. You won’t be able to edit them on the General settings page anymore when using this method.
2) Second Method
Edit functions.php
If you have access to the site via FTP, then this method will help you quickly get a site back up and running, if you changed those values incorrectly.
FTP to the site, and get a copy of the active theme’s functions.php file. You’re going to edit it in a simple text editor and upload it back to the site.
Add these two lines to the file, immediately after the initial “<?php” line:
update_option( 'siteurl', 'http://example.com' );
update_option( 'home', 'http://example.com' );
Use your own URL instead of example.com, obviously.
Upload the file back to your site, in the same location. FileZilla offers a handy “edit file” function to do all of the above rapidly; if you can use that, do so.
Load the login or admin page a couple of times. The site should come back up.
Important! Do not leave this code in the functions.php file. Remove them after the site is up and running again.
Note: If your theme doesn’t have a functions.php file create a new one with a text editor. Add the <?php tag and the two lines using your own URL instead of example.com:
<?php
update_option( 'siteurl', 'http://example.com' );
update_option( 'home', 'http://example.com' );
Upload this file to your theme directory. Remove the lines or the remove the file after the site is up and running again.
For more details Here I have shared the WordPress org Support Link
If you have access to the database, you can go into PHPMyAdmin, click on wp_options, then search for both home and site_url (or possibly siteurl) and you can change your values there as well. The previous commenter's methods will also work but using functions.php is unnecessary and using wp-config is a temporary fix, in my opinion.
I have problem with running javascript codes in may pages.
I tried testing my code in xampp and it was working.
but I can not see them when I add them to my pages or my posts in my host and I installed wordpress again and it wasn't working.
Please help me
There are a few ways you can include JavaScript files in WordPress, I will give you one example using your child theme.
First you need to validate whether or not you actually have a child theme. Use FTP to login to you server and go to the wp-contents/themes directory. There you will see all your installed themes (in your case betheme). If you do not have a child theme follow these steps:
Create a new directory in your themes folder (betheme-child).
Upload your JavaScript file in this directory (for example script.js)
Create a new file called functions.php and add the following code to it: (surrounded by php opening and closing tags):
add_action('wp_enqueue_scripts', 'enqueue_child_scripts');
function enqueue_child_scripts() {
wp_enqueue_script('child-script', get_template_directory_uri() . '/script.js');
}
Login to your wp-admin and navigate to your themes
Enable your child theme instead of your normal theme.
Go to the front-page of your website, look at the page source and check if your JavaScript file is being loaded.
If you are using cloudflare, turn off minify JS.
I have a wordpress site in which I want to redirect all the FILE NOT FOUND 404s.
example : wwww.xyz.com/abc.php
if abc.php does not exist on the server it should be redirected to home page.
I have successfully redirected page not found 404s but having issues in redirecting this one. Can it be done using any plugin?
Why not create a 404.php page within your theme and then put in the following code to redirect?
<?php
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
?>
Hope this helps.
For redirection there is a nice WordPress plugin which can do that quite simply - https://wordpress.org/plugins/simple-301-redirects/
But if the issue is that the webserver is showing the default 404 page and not the one within WordPress you should check if .htaccess is present, mod_rewrite is installed . Are the existing pages in WP redirecting properly?
I'm trying to make a archive page for my blog.
I have my wordpress installation at: domain.com,
The blog is on domain.com/blog
and all other pages / custom post types are working from the root
For instance I have a custom post type for clients, this cpt works on domain.com/clients with a for archive-clients.php an overview page.
Now I'm trying to make a same page for the blog but nothing is working.
The only thing that works is my index.php.
You should be able to create a file named archive.php
EDIT: more info below
If you want to have a special link for the /blog page create an extra template:
Wordpress looks for the template name to index page template listings. Example:
/*
Template Name: Blog Archive
*/
Technically, you can copy the code from the index.php or archive.php, create another file, put the copied code in it, and at the very top of the file inside of opening and closing php tags have template name code. This will allow you to create a new page named blog (or anything else) in the wordpress admin area, then you can assign it to a template named blog archive.
More information:
http://codex.wordpress.org/Page_Templates
http://codex.wordpress.org/Template_Hierarchy
ive created an enter page for wordpress and what im wondering is how do i put it as the index page when the index page has the code to load wordpress? how and where do i place the enter page? thanks
There's setting in wordpress admin page which doesn't involve manual setting in .htaccess.
Besides the fact that splash pages are so very wrong... (the only defensible exception I can think of is for an adults only site that asks you if you are 18 or older), you could set it up as index.html and ensure your .htaccess has
DirectoryIndex index.html index.php
Things that you could do ...
Put the splash page on /index.html and put wordpress in /site/ (or something else innocuous); put a redirect on /index.html -> /site/ after the splash is done.
Put the splash page as a page named 'Splash' in Wordpress, with its own template. In the Reading settings page, set the 'Front Page' as 'Splash'. Redirect to the index page after the splash is done.
Put the splash page as a page named 'Splash' in Wordpress, with its own template. Modify index.php in your theme to check for a cookie -- if the cookie isn't present, load the Splash page instead of processing the Wordpress Loop. Once the splash page is done, set the cookie and redirect to the index page.
A route that's worked for me is to bypass the WordPress core files and do everything from your theme folder. So, for example, in your theme folder (WEBROOT/wp-content/themes/YOURTHEMEFOLDER) add a home.php file, and in that file, add whatever code you'd like to use for that first page. By default, WordPress looks for a file named home.php, if it finds it, it will use it first, if it doesn't find it, it will use the index.php next. Since you'd like to use both, it will use home.php for your home page / site default page & then every other page can use the index.php page.
Also, there's other template files that WordPress will look towards before it displays the index.php page - for a detailed list / illustration of this go to http://codex.wordpress.org/Template_Hierarchy & scroll down a little.