Questions tagged [template-redirect]
The template-redirect tag has no usage guidance.
99
questions
0
votes
0
answers
12
views
Trying to re-direct users to specific page based on an ACF variable
I have a case where I have an ACF variable that is stored within a users profile and based on that variables state I need to redirect to one of two pages once the user logs in. This is just a true or ...
1
vote
0
answers
26
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 ...
0
votes
1
answer
22
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 ...
1
vote
0
answers
29
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/...
0
votes
0
answers
25
views
How to make WordPress search page use a relative path
I am working with a WP blog hosted on a subdomain (eg. wp.foo.com). The primary domain (eg. foo.com) is a non-WP platform running a main app/service. For blog content, however, the main platform uses ...
1
vote
1
answer
21
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 ...
0
votes
0
answers
21
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:
...
0
votes
0
answers
46
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 ...
0
votes
1
answer
26
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 ...
0
votes
2
answers
62
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 ...
0
votes
0
answers
52
views
using add_filter in a template_redirect function?
I have certain pages that I would like to filter, replacing some tags, with a value. Rather than attempting to filter every page, I only want some pages, but to make it use even less resources (not ...
0
votes
2
answers
199
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 - ...
0
votes
0
answers
16
views
Get posts on template redirect
I'm trying to validate some $_GET parameters before letting the user view a particular page. In the actual template file, this code works:
$user = get_user_by('ID', $_GET['sscp']);
$args = [
'...
0
votes
1
answer
52
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 ...
0
votes
1
answer
24
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 ...
0
votes
1
answer
27
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/...
0
votes
1
answer
121
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....
1
vote
1
answer
122
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 '...
1
vote
1
answer
172
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['...
0
votes
0
answers
28
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 ...
0
votes
0
answers
14
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 ...
0
votes
1
answer
35
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 ...
1
vote
2
answers
725
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 ...
0
votes
0
answers
24
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() {
...
1
vote
1
answer
420
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 ...
-1
votes
1
answer
106
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 : ...
0
votes
0
answers
396
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 ...
0
votes
1
answer
1k
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 ...
0
votes
1
answer
125
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....
0
votes
2
answers
98
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 ...
0
votes
1
answer
301
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()
{
?&...
0
votes
1
answer
180
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 ...
0
votes
1
answer
457
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 ...
0
votes
1
answer
21
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.
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 ...
1
vote
1
answer
344
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 ...
1
vote
1
answer
12k
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 ...
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?
0
votes
1
answer
70
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 ...
0
votes
1
answer
312
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 ...
0
votes
1
answer
3k
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 ){
...
0
votes
3
answers
2k
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 ...
1
vote
0
answers
518
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 ...
5
votes
1
answer
6k
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 ...
1
vote
1
answer
610
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 ...
0
votes
0
answers
664
views
Force CSV download with template_redirect
I'm struggling to get a dynamically-generated CSV to download with a template_redirect. It seems to work (if not this exact version, another similar version) when it does not go through Wordpress, e.g ...
0
votes
1
answer
679
views
template_redirect() doesn't seem to be working
kind of a rookie question but here goes:
I'm working on a Wordpress theme from scratch on my local machine, and I'm setting up a static page for the Blog. I have my archive.php file for all the posts ...
1
vote
1
answer
403
views
Setup template_redirect using has_term when NO term assigned
we have a redirect function for a Custom Post Type to redirect single view pages for certain terms back to their archive landing page. There should only be single view pages for one specific taxonomy, ...
0
votes
1
answer
48
views
how to show post content with post name in sidebar?
I started working on a wordpress website, I need to show 20 words from every post with post name in Sidebar.
I am new to wordpress, I am finding difficult to do it.
1
vote
0
answers
2k
views
How do I determine what is causing a redirect for a given page?
This is probably a face palm question. On Wordpress 4.4. the link
http://example.com/blog
...redirects to:
http://example.com/category/general
...ie. it's redirecting to archive.php and ...