I was doing some research on wordpress tags and categories and the below script which is needed for redirecting single posts related categoies and tags to be redirected to the post itself in wordpress. Below code is wordpress redirect without plugin needed. it does not add more overhead on server performance.
Table of Contents
function redirect_to_post(){
global $wp_query;
if( is_archive() && $wp_query->post_count == 1 ){
the_post();
$post_url = get_permalink();
wp_redirect( $post_url );
}
} add_action(‘template_redirect’, ‘redirect_to_post’);
Above can also used to redirect all posts of category to any single page etc… its just needs to be changed accordingly at $post_url line. Please let me know if you need more help on this.
How to install of FireFox browser using PowerShell Sometimes you would like to install Firefox…
Quick way to install chrome on windows with Powershell? Launch the Powershell and run below…
How to Fix PowerShell Script Not Digitally Signed Error? When a script with a .ps1…
Powershell Cheat Sheet for beginners PowerShell has become something of an ace in the hole…
Today we discuss one of a few questions a lot of sysadmins and IT Admins…
Backing Up an SQL Database with PowerShell Before making any changes in the production environment,…
This website uses cookies.