Questions tagged [template-redirect]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
48
votes
2answers
74k views

How to create custom URL routes?

I have a very peculiar requirement, hopefully, I can explain it without being too confusing. I created a page template where I list some properties I get from an external XML file, so far no problems, ...
19
votes
6answers
12k views

single-{$post_type}-{slug}.php for custom post types

My favorite part of the Wordpress template hierarchy is the ability to quickly create template files for pages by slug, without having to edit the page in Wordpress to select a template. We can ...
9
votes
1answer
11k views

Custom Post Types and template_redirect

I have two custom post types (e.g. post_type_1 and post_type_2) that I would like to redirect to independent templates (single-post_type_1.php and single-post_type_2.php) to handle their display. I ...
6
votes
1answer
11k views

template_include (overriding default plugin templates via current theme)

This is an extension of this question/answer. A comment on that question references that template_include is preferred to template_redirect when loading templates from a plug-in. However, hanging ...
4
votes
1answer
3k views

How do I redirect /search/ to wordpress search template?

I have a typical Wordpress site, with a typical Search page template set up which uses the typical GET format <form id="searchform" action="http://example.com" method="get"> <...
4
votes
3answers
923 views

Wordpress multisite,several different languages,page redirect?

I have something like this http://example.com/en , http://example.com/fr and http://example.com/es for example I would like if I'm on this page http://example.com/en/about-us/ when I click on other ...
3
votes
1answer
2k views

Want to redirect if search query match exact title of any post

I am using WordPress 3.3.1 and new to this system. I want to redirect the search query to the post if query exactly matches post title of some post. I also want it to run before any search query ...
3
votes
1answer
2k 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 ...
3
votes
4answers
12k views

redirect wp-login.php to another page

I would like to redirect this page wp-login.php to /login page. So when a user clicks on a link like this <a href="/wp-login.php">login</a>, wordpress will redirect him to /register . I ...
2
votes
2answers
2k views

wp_head() not including styles and javascripts after a template redirect

I am using the template_redirect action to redirect a user to a custom template which has no header, sidebar or footer (the intent is for it to be in an iframe as a dialog box). After I done the ...
1
vote
1answer
4k 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 ...
1
vote
3answers
3k views

Proper method to restrict non logged users into certain pages

I was wondering which is the correct method to do this and which action hook should i use. I have custom login/register pages so if the user try to go to a forbidden page and its not logged in i ...
1
vote
1answer
3k views

Change template dynamically

Is it possible to change the template loaded for a page, as it loads, without having to change the record in the database? I suspect it can be done with the template_redirect action, and the will ...
1
vote
4answers
1k views

Where does the 404 redirection happen?

Can someone please tell me where the 404 redirection occurs? I am wanting to redirect to a custom template.php instead of the 404 page. Is this possible to do? If it is can some one provide me with ...
1
vote
1answer
174 views

Include a file before current template file

I would like to include two files before and after current template. I am using template_redirect to do this, But when I call get_current_template() inside template_redirect it returns nothing. is ...
1
vote
2answers
1k views

Are Category or Tag Archive Pages Possible?

Currently /category and /tag 404 if you hit them directly. Is it possible to create a theme template to handle what would display on it? Mark Jaquith - http://twitter.com/#!/markjaquith/status/...
1
vote
1answer
96 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
0answers
163 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 ...
1
vote
1answer
247 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 ...
1
vote
1answer
174 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, ...
1
vote
0answers
745 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 ...
1
vote
0answers
48 views

Why does my URL rewriting only work using two different methods?

For our website, I've built out some "pages" using URL rewriting, with some code that I found here. It worked to have two of these special pages, but it's not working when I try to add a third. I've ...
1
vote
1answer
581 views

How to pass a message using template_redirect

I'm using the following function to redirect a post to another using custom field. It's working just fine until I added the line#8 to pass an ID so that I can grab it in to the post (to where was ...
1
vote
0answers
35 views

Redirect on Empty Query Var [duplicate]

I have a plugin with two rewrite rules: public static function cp_libdatabases_add_rewrites(){ $options = get_option( 'libdatabases_plugin_options' ); $staff_url = $options['staff_url']; ...
1
vote
1answer
171 views

URL rewriting with custom user meta “/%shop_name%/gallery/%gallery%”

I have created a custom user meta = shop_name in User Profile and custom post type gallery The default URL of the post is http://localhost/gallery/%gallery% which i have modified to below given URL ...
1
vote
1answer
941 views

Force HTTPS 301 redirect with hook

I am trying to force a 301 https redirect with hooking into the 'template redirect' function. I want not doing it a htaccess because when I update my permalinks, htaccess with https redirect ...
1
vote
1answer
502 views

Pre-Populate $wp_query settings with custom rewrite rules and custom template_redirect

I'm currently working on a file browser plugin which requires frontend editing capabilities for a registered user. For this scenario, I have registered some custom rewrite rules for my custom post ...
1
vote
2answers
340 views

Common single page template options

I am developing a common theme for 25 websites, the default requirements are done. Each site has got different single post template. I need to group it as a single theme so i don't need to hard-code ...
1
vote
1answer
410 views

Different Template based on HTTP Referer

He Guys, i've been looking for a way to show a different Page-Template based on HTTP Referer or maybe the User Agent or what ever. I'm planning an Image-Gallery which should be shown in a Fancybox. ...
0
votes
3answers
5k views

!is_admin() condition turns true in admin pages

I need users to redirect to login if not logged and once they are, redirect them to backend if they try to see front end pages. This is my code: add_action( 'template_redirect', function () { if(...
0
votes
2answers
251 views

How should I approach changing the template & $query as part of a shortcode's execution?

I am working on a project where I need to be able to change the template being used if a given shortcode is used. To complicate things more, the plugin must also be able to rewrite $query if this same ...
0
votes
3answers
2k views

make permalink go to a custom single.php file

hope somebody can help me with this because I am struggling for a while. I want to use two single.php on my website, one to display the regular posts and another to display some products that I will ...
0
votes
1answer
16 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
1answer
39 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
1answer
1k 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
1answer
36 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.
0
votes
1answer
243 views

Template Redirect to /2015 to use page template

We work with non-profits and come across this issue a lot. We need to use a page template for the url structure domain.com/2015 where we'll be adding an "end of year" report. We're not using the ...
0
votes
1answer
816 views

template_redirect to accompany with a shortcode

In one of my plugin's shortcode I'm handing user login / registration on the fly with a post submission. So the whole thing is happening within the shortcode like: <?php function this_shortcode() {...
0
votes
1answer
2k views

how to load posts to a custom post template after using template_redirect or template_include

I need to use the URL parameter ?m=1 to load every page of my wordpress with a different template but the problem is that I can't pull the text and posts that can be accessed using the canonical URL I ...
0
votes
1answer
289 views

Redirect not logged in users if they are on a specific page and category

Following code is working fine for pages but how to add category id as well with pages in the following code. add_action( 'template_redirect', function() { if ( is_user_logged_in() || ! is_page() )...
0
votes
1answer
389 views

Template_redirect for child custom post types

I currently have a custom post type called 'Services' which has two levels (parent and child). I need to load three different templates within this post type (1 for the parent, and two different ones ...
0
votes
1answer
35 views

Page that links to category content

I have a page called: fruit...then I have three child pages called cherry, lemon, and peach. I also have a category called fruit, and three child categories called cherry, lemon, and peach. What I am ...
0
votes
1answer
968 views

Call another page in forms

I am doing some practice for WordPress plugin. In plugin I am working on a form and what I need is to call another page on submission. I have tried that but nothing seems to work. <form method = "...
0
votes
2answers
888 views

Proper Way to Enqueue CSS for Front Page - template_redirect in functions.php?

I want to load some specific css to change color of body element of front/home page of WP. Within my themes function file, the following code seems to work, but can someone please tell me if it is "...
0
votes
2answers
156 views

Redirect returning users to a certain page?

Is there a way to redirect users returning to the site who are already logged in? Assuming something like: function returning_redirect() { //code here } add_action('auth_cookie_valid', '...
0
votes
1answer
69 views

Add code to template dynamically

I'm working on something these days I do not know if it's good practise. My plugin has to take some templates and put them into theme instead of existing header.php and footer.php. EDIT2 : Not a good ...
0
votes
1answer
28 views

How can recognize post's category?

I want my plugin to recognize post's categories before post is loaded. i wrote this code but it works in category page not in post's page with the category is specified from me. function checkUser() ...
0
votes
3answers
2k views

Category link redirect to custom template page instead of index.php?

I want to make template page for my custom taxonomy. I have custom taxonomy categories listed as navigation links. It's the country list (China, Slovenia, Serbia...). Every of this categories has ...
0
votes
1answer
4k views

Template redirect template loaded, but the header 404

I've created a template redirect for a given url, ex.: test.com/test Test is page is not exists, i'm just checking the url from query_vars, if its match, i load the template with include(file.php);...
0
votes
1answer
1k views

Default taxonomy template in plugin, override in theme

Building off of this question/answer, I've sucessfully implemented the single view for my custom post types, but I'd also like to offer the same thing for taxonomies. I've looked through the docs and ...