Skip to content

Clear2All

Clear2All Blog is for technical articles for everyone. It is dedicated in providing the highest quality and most in-depth material to boost your career or to make one more productive.
  • Home
  • Windows IT
  • Exchange
  • Office 365
  • Google Cloud
  • About Us
  • Contact_us

Clear2All

Clear2All Blog is for technical articles for everyone. It is dedicated in providing the highest quality and most in-depth material to boost your career or to make one more productive.
  • Home
  • Windows IT
  • Exchange
  • Office 365
  • Google Cloud
  • About Us
  • Contact_us

How to Redirect if Category or Tag Contains Only One Post WordPress

  • Vamshi B Vamshi B
  • June 29, 2021
  • Blogging

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

  • Below code can be added to child theme(recommended) or to your theme’s functions.php file
  • Note: Child theme’s are safe in WordPress to be sure not to break anything all at once when doing customization.
  • If you need more of these snippets like below for customization then comment and i will post shortly but comment if needed urgently.

Below code can be added to child theme(recommended) or to your theme’s functions.php file

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’);

Note: Child theme’s are safe in WordPress to be sure not to break anything all at once when doing customization.

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.

If you need more of these snippets like below for customization then comment and i will post shortly but comment if needed urgently.

  1. wordpress redirect page to external url,
  2. wordpress redirect hook, wordpress redirect plugin
  3. redirect wordpress site to another url,
  4. wordpress 301 redirect,
  5. wordpress 301 redirect enabled,
  6. wordpress page template redirect,
  7. wordpress redirect referrer,
  8. wordpress redirect to new domain
  9. wordpress redirect to another page
  10. wordpress redirect http to https
  11. wordpress redirect url
  12. wordpress redirect after login
  13. wordpress redirect to https
  14. wordpress redirect after login based on role
  15. wordpress redirect all pages to one page
  16. wordpress redirect admin page
  17. wordpress redirect after submit comment
  18. wordpress redirect all pages to homepage
  19. wordpress redirect a page

Tags:redirect wordpress site to another urlwordpress 301 redirectwordpress 301 redirect enabledwordpress page template redirectwordpress redirect a pagewordpress redirect admin pagewordpress redirect after loginwordpress redirect after logoutwordpress redirect after submit commentwordpress redirect all pages to homepagewordpress redirect all pages to one pagewordpress redirect hookwordpress redirect page to external urlwordpress redirect referrerwordpress redirect to new domainwordpress redirect urlwordpress redirect without pluginwordpress site hacked redirectwordpress site redirectwordpress site redirecting to another websitewordpress site redirecting to localhostwordpress site redirecting to old urlwordpress site redirecting to spamwordpress site redirecting to wp-admin/install.php

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Please follow & like us :)

RSS
Follow by Email
Facebook
fb-share-icon
Twitter
Tweet

Recent Posts

  • How to install Firefox browser using Powershell
  • How to install chrome with Powershell?
  • How to Fix PowerShell Script Not Digitally Signed Error?
  • Powershell Cheat Sheet for beginners
  • Can you use Linux commands in Powershell?
  • Backing Up an SQL Database with PowerShell
  • Powershell Get-Eventlog Get-Process and Stop-Process commands
  • How WordFence Security Plugin makes WordPress Secure and its Review
  • Google Cloud WordPress ftp setup step by step
  • Best Free WordPress Themes Available in 2021 and What is expected ?

Clear 2 All Blog is for everyone for technical articles

Clear2all | Copyright by Clear2all

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT