Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [template-redirect]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
21 views

Not displaying the wp_query object for the following code in the frontend

add_action('template_redirect', function () { global $wp_query; echo '<pre>'; print_r($wp_query); echo '</pre>'; die; });
Soumyadeep Chandra's user avatar
0 votes
1 answer
11 views

Where does the redirect from shortlink to permalink happen?

When requesting short urls they are redirected to their matching permalink, for instances : shortlink permalink /?cat=category_id /category_base/category_slug /?p=post_or_page_id /custom_structure/...
challet's user avatar
  • 111
0 votes
2 answers
81 views

How to redirect my homepage

My wordpress theme uses templates but I want to temporarily redirect the homepage which uses the template "page.php" to a category page which uses a template file. Can I use a redirect ...
Amena's user avatar
  • 1
0 votes
1 answer
677 views

How to stop wordpress from redirecting from the post's old slug after changing title and slug?

After changing a post's title/slug from mysite.com/name to mysite.com/new-name, the old slug mysite.com/name is now redirecting to the new one mysite.com/new-name, and I don't want that to happen. I ...
cashrunner's user avatar
0 votes
1 answer
295 views

Redirect wp-sitemap.xml not working

I'd like to redirect wp-sitemap.xml to a custom sitemap file. I'm using template_redirect but the request isn't redirected. I attempted to debug it with die() but it doesn't work either. function ...
Ryan's user avatar
  • 53
0 votes
1 answer
68 views

Load a specific post if user tries to access 404 page

First, I'm not trying to redirect the user as I don't want the URL to change - think of it as an include rather than a redirect. Second, I would want to have control over the content, title, etc. So ...
Roz's user avatar
  • 21
0 votes
1 answer
178 views

Template Redirect Function Only Working When Logged In

I added a template_redirect to my functions.php file, which redirects private staff members to a "Staff No Longer Available" page. However, my code only works when I am logged in. Am I ...
Michelle's user avatar
1 vote
2 answers
424 views

Creating FPDF directly in the browser using template_rediect

I am trying to create a pdf using fpdf, which opens in a browser window. Ultimately, the data will be passed from a form submit to a non-existent WP page called pdf. I am checking for this in ...
StripyTiger's user avatar
0 votes
1 answer
184 views

send popup after wp_redirect()

Hello Wordpress Developer, I want to ask about how to send popup after wp_redirect(); I'm sending link to user for verify. I just want to let user know that the verify process is done. Here is the ...
Hendra's user avatar
  • 15
1 vote
0 answers
70 views

Serve specific "template" page at any URL that ends in its slug

Still new to WordPress, so please go easy on me. Goal: Prevent users of a specific role from viewing other custom post types made by users of same role. Intended solution: Modify the URL and redirect ...
Ryan Cochran's user avatar
0 votes
1 answer
131 views

Redirect page without changing the url

I have a page running a custom shortcode. When an element on the page is clicked I am pushing a new url into the browser (using history.pushstate) and displaying the content in the same window. If ...
StripyTiger's user avatar
1 vote
0 answers
42 views

Adding rewrite rule dynamically for search results redirecting to 404 URL

We need the search url structure like the below URL : https://siteurl.com/in/chennai/accountant/ We have already a post url with same structure for single post detail page URL : https://siteurl.com/in/...
RagEsh's user avatar
  • 11
1 vote
1 answer
159 views

How to correctly detect accessing wp-content/uploads?

Not sure if this is a stupid question or not; however, I've been trying to detect when a user accesses a PDF. I want to be able to know how often a user is accessing specific PDF files. I have been ...
please_help_me's user avatar
0 votes
0 answers
70 views

Template_redirect works, but headers aren't sent when checking via cURL

I'm creating a 307 redirect to maintenance page for when my site goes through maintenance. My PHP class is included in functions.php, and gets instantiated immediately. In my __construct, I call: ...
user1702965's user avatar
0 votes
0 answers
135 views

auth_redirect() doesn't send users to the page where they orginally tried to acces

In the site I am building, I'm using "theme my plugin" so I could make my own login, logout, registration pages. For the login form, I used the default wp_login_form input names, and the ...
T3mmX's user avatar
  • 23
0 votes
1 answer
249 views

Custom Login page, redirection and restrictions

I'm having some issues with my custom login page with redirections and restrictions. Any user can browse a 'community' page but they can't access the 'distributors' pages. I have set a rule so if ...
Maluco's user avatar
  • 1
1 vote
2 answers
169 views

Redirect Users who aren't logged in, aren't post authors and aren't admin. Frontend

Very new to PHP and I'm trying to do the following through a snippets plugin but keep getting critical errors: Restrict all non-logged in users to home, about and pricing pages. If attempting to ...
Jake Billington's user avatar
0 votes
2 answers
884 views

How to redirect to category page if page does not exists?

In my current case, the system try to find a page and show 404 if it does not find. I would like with the same url... like https://example.com/{{slug}}/ Check if a page with this slug exists : Yes - ...
J.BizMai's user avatar
  • 870
0 votes
1 answer
149 views

Page get parameter doesn't work with is_single() function

If exist the page parameter in the blog post, I have to redirect to the 404 page instead of current post URL. I tried to check the current page type (is singular) and try to get page parameter in the ...
MT09's user avatar
  • 13
0 votes
1 answer
132 views

Intercept loading of a certain page

Depending on whether user registration is enabled on my site or not, I want to prevent loading of my custom login form and display a popup instead telling the user that registration is disabled. I ...
Razzupaltuff's user avatar
0 votes
1 answer
60 views

Why does the $_GET parameter ?search forward the front-page to the archive/blog page

I need the $_GET parameter ?search for my front-page for a third party plugin. Whenever I enter http://wp-site.tld/?search=foo I get redirected to the blog/archive page. If I enter http://wp-site.tld/...
BonisTech's user avatar
  • 272
0 votes
1 answer
296 views

Detect if requested page is PWA on server side

I'm trying to determine if the user is browsing PWA on server side. On client side I can check if the browser mode is standalone via JavaScript and detect PWA, but on server side this is not an option....
DaftPlug's user avatar
1 vote
1 answer
290 views

Redirect all child taxonomy to its parent

Is it possible to automatically redirect a child taxonomy to its parent, therefore not having a public page at all for the child taxonomy? Example: I have a taxonomy called venue, this is set up with '...
robwatson_dev's user avatar
1 vote
1 answer
448 views

Redirect specific page in Wordpress for first time visit

I tried the following to redirect one page on the first visit: function check_for_redirect() { if( is_page( 8219 ) ) $days_to_expire = 30; if (!is_admin() && !isset($_COOKIE['...
Rens's user avatar
  • 11
0 votes
0 answers
42 views

I want to replace after WordPress is completely loaded

The replacement process is always done with the following code. You can also use filter hooks, but some themes are hard-coded and you can't use filters. So I'm using this code (template_redirect ...
nodoka's user avatar
  • 1
0 votes
0 answers
18 views

How to add a switch to admin area which enables/disables crisis-mode: Redirect all traffic to certain page if switch is enabled

Case: There is natural disaster or terrorist attack etc. Admin logins to site and enables "crisis mode". All traffic gets redirected to crisis page. I found this code from another answer ...
Antti Mäkelä's user avatar
0 votes
1 answer
105 views

Redirect logged in users from a custom post type archive page if they don't have a specific role

I have a Custom Post Type named flashcard and post of that type are listed by an archive-flashcard.php template. The bellow function force flashcard posts to be listed only for posts authors (they ...
Yuri's user avatar
  • 1,121
0 votes
2 answers
2k views

URL Rewriting for PHP script on an image URL

I built an image randomizer so that when I open a .php file in a URL that it displays the image with readfile($randomImage);. This works locally but when I upload it to the server it gets blocked by ...
w.jelsma's user avatar
0 votes
0 answers
30 views

Template includes

I want to use custom template redirects for urls such as http://example.com/foo and http://example.com/foo/bar I'm using add_rewrite_rule function for this add_action('init', function() { ...
Alexey Galkevych's user avatar
1 vote
1 answer
604 views

how to block direct access to multiple thank you pages?

I have multiple contact forms in my wordpress website and have a different thankyou page for each. So, i want to prevent direct access of thankyou pages by just entering urls. I want if the user fills ...
Ujjawal Poonia's user avatar
-1 votes
1 answer
152 views

Redirect to a subdirectory frontpage using without using a WP plugin- what files to edit, and how?

My situation I have a multisite setup, where I use subdirectories for different languages. I use the main homepage for English and subdirectories for other languages, as follows: mywesbite.com : ...
yarimoto's user avatar
  • 103
0 votes
0 answers
617 views

Polylang will not allow changing of language without translation

I am using polylang plugin to translate a website which uses custom theme. We are using custom post type. We want to use custom translation for that post type. We will not use polylang to translate ...
Latif Pala's user avatar
0 votes
1 answer
2k views

WooCommerce – template_redirect if is_checkout AND order has been paid?

In my WooCommerce store I would like to redirect to a custom 'thank you page' after payment has been completed. I'm using this code: add_action( 'template_redirect', 'myfunction' ); function ...
Jussi's user avatar
  • 23
0 votes
1 answer
216 views

How to customize file path for 404 redirection in php?

I made a plugin with a custom post type postcard. Most of postcards are private. I would like to redirect the logged out user in a specific php file inside my plugin instead of the 404.php or achive....
J.BizMai's user avatar
  • 870
0 votes
2 answers
132 views

Redirect user to a custom url after logged in

I'm using "Passwordless Login with OTP / SMS & Email - Facebook Account Kit" for login. I want to redirect user to http://www.domain.com/author/<username>/screen after they log in this is ...
Dreammedia Rulz's user avatar
0 votes
1 answer
513 views

wp_enqueue_style on template_redirect level?

I am using the following function, which works fine, in order to provide a minimal output of HTML at a WordPress installation of mine: add_action( 'template_redirect', 'test' ); function test() { ?&...
JohnnyBratsoni's user avatar
1 vote
1 answer
284 views

How to redirect (301) trashed post to it's parent taxonomy TERM ARCHIVE instead of 404 page

I have a taxonomy called "Sports", that includes terms: Football, Rugby, Tennis... What I want to achieve is when (for instance) a post that has the term football is trashed and a visitor try access ...
Charaf Web's user avatar
0 votes
1 answer
1k views

Custom URL routes

I'm a newbie in Wordpress, so excuse me if I ask a noob question. I want to redirect some of the URLs to a specific page (single-deal.php). Now, these set of URLs (regex provided for these URLS) does ...
Praful Bagai's user avatar
0 votes
1 answer
29 views

Internal redirect from page to category

I want to implement a page, let's say /today-deals that will show all posts under today category, like if we were navigating to /category/deals-for-october-31-2018 but without changing the URL.
Javier Marín's user avatar
0 votes
1 answer
1k views

Redirect to first child in menu

I have the following page hierarchy: Page Grandparent (This page) Page Parent 1 (Should direct here) Page Parent 2 Page Child Page Child Page Parent 3 Page Parent 4 My parent and child pages have ...
Sam's user avatar
  • 2,146
1 vote
1 answer
506 views

Custom pagination structure

Currently my pagination works like http://example.com/city/usa/ #for page 1 http://example.com/city/usa/page/2 http://example.com/city/usa/page/3 ...and so on I want to change ...
Parixit's user avatar
  • 133
1 vote
1 answer
14k views

Redirect the single product page link to the shop page

I am using the WooCommerce plugin. I want to redirect the user to shop page if they try to access the product link. For example, this is the product link: http://www.example.com/product/av and shop ...
Himani's user avatar
  • 37
0 votes
3 answers
2k views

How to redirect home page to another page after login for all user?

How to change home page to another page after login for all user roles, not a specific one?
Jalees Ahmad's user avatar
0 votes
1 answer
78 views

wp-admin redirects to standard wordpress page

I installed a Wordpress theme (NRGhost). It installs a plugin to use shortcodes (NRGhost Plugins) and other features. The plugin creates a custom redirect on wp-admin and redirects it to a custom ...
arximughal's user avatar
0 votes
2 answers
518 views

redirect_to not Including Hashtag from URL

When non-logged-in users attempt to go to a forum topic that requires a login, I'm trying to redirect them to that topic after they've logged in. But I can't seem to get the anchor/hashtag to remain ...
Sinclair's user avatar
0 votes
1 answer
4k views

How to override a query and display specific page by ID?

I need to build a offline page and first idea was to simply get desired page ID and do wp_redirect but that leaves a URL of the page to redirect to. function _action_offline_mode( $template ){ ...
Benn's user avatar
  • 1,043
1 vote
3 answers
3k views

force download a file in template_redirect hook

in my functions.php file I've added a custom action for the template_redirect hook which must force download a file stored on the server. The code of the download works fine when it is in a simple PHP ...
superfive33's user avatar
1 vote
0 answers
662 views

Redirect custom post type category to other custom post type category

Two similar custom post types have been created by my theme and a plugin I'm using. These basically customizing the categories post type. They are as follows: product-category listing-category I am ...
acctindie's user avatar
5 votes
1 answer
8k views

stop redirection on /wp-admin call to /wp-login

I am building a website, with wordpress+buddypress (latest version). In this website, I have my own custom login|signup|resetpass forms, and i do not want to link them to back-end wp-forms. And I ...
Poofy's user avatar
  • 69
0 votes
1 answer
1k views

wp_redirect on base wp-admin and login

UPDATE: I've done some more research on my problem and have narrowed down the problem further. The question below has been very rewritten from the original. I'm trying set up a plugin to redirect ALL ...
CGriffin's user avatar
  • 131