Articles of template redirect

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 there a way to solve this ?? here is my code: // current template file add_filter( ‘template_include’, ‘var_template_include’, 1000 ); function var_template_include( $t ){ $GLOBALS[‘current_theme_template’] […]

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 probably have something to do with the template-loader.php file in the WP core, but I can’t figure it out. […]

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 a solution. Thanks Ravi

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 will redirect him to a login page. Currently on my functions.php i got the following: […]

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 redirect though, I could not seem to get all the enqueued JS and CSS to list. […]

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 found this function and modified it : add_action(‘init’,’custom_login’); function custom_login(){ global $pagenow; if (( ‘wp-login.php’ == $pagenow ) && (!is_user_logged_in())) { wp_redirect(‘/login’); exit(); } […]

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 function and hooks or filter. I have made some changes in query.php in include folder $search […]

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 this to template_include is breaking everything on the site (any other page view) except the layouts that using the layout override http://pastebin.com/LWpSrfim but using template_include just prepends content […]

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 language link,just to redirect to that language,but to stay on same page,for example if I click on link that will go to french site,and I’m currently on http://example.com/en/about-us/, I […]

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”> <input id=”s” type=”text” name=”s” placeholder=”Search Again”> </form> For users’ convenience, I’d like to have the following url redirect to the search page template: http://example.com/search/ But since there is no /search page […]