Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
How to avoid loop when redirecting WordPress post?

I have a redirection problem on WordPress, I want to show a different page to users that come from search engines instead of those who come directly

Have the "Insert PHP Code Snippet" plugin for this purpose.

The script is :

<?php 
 
##Begin of conditions
 
##End of conditions

## If conditions Met above

If(isUserValid() === "true") {
    header("Location: https://example.com"); }  #external URL

## If conditions Not Met above
 
else 
{    
    header("Location: https://example.net/post"); } #wordpress post

So the problem here, the PHP code is inserted in that post https://example.net/post If the conditions are okay, the redirection goes smooth But when the conditions aren't met, I'm getting a redirection loop and error. Because the header is the same where I've put the code.

Is there a way to write a code that can disable the PHP code after the first redirection?

For SEO I need the redirection to be done to the same post, to avoid losing ranking.

EDIT: I need to replace this line

header("Location: https://example.net/post"); } #wordpress post

With another line, that will let you stay on the same page if conditions aren't met. That will fix my issue.

Thank you

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!