1

I currently use SEO plugin but I need some extra help because the plugin cannot help me in this case.

I have a page that displays data based on a URL parameter (ie. http://example.com/?user=john25). I would like to incorporate this parameter to the page title. That is, I want the page title to become something like "Entries from john25".

I would appreciate some help on how to achieve this.

1

You could do something like this in your header.php file (or where ever you are setting your page titles in your templates)

<?php if (isset($_GET['user'])) : ?>
<title>Entries from <?php echo(htmlspecialchars($_GET['user'], ENT_QUOTES)) ?></title>
<?php else: ?>
<title>Normal page title here</title>
<?php endif; ?>

Without more info on what plugin you are using, or how your page titles are currently being set, this is the best I can recommend

  • Please do not delete an answer and repost the same content as a new answer. Rather file an edit to the existing answer if you need to add/remove or change something. Continuing this will get your account suspended by the system. (Hint: 10K+ users can see deleted posts ;-)). – Pieter Goosen Oct 11 '15 at 14:03
  • 3
    NEVER EVER use values from a GET variable without sanitizing and validating it. It can contain malicious code, which will infect your site – Pieter Goosen Oct 11 '15 at 14:05
  • Thanks Pieter for the advice, but the answer was accidentally reposted due to miss clicking after going back in my browser, the original was edited. – RiaanZA Oct 11 '15 at 14:30
  • As for sanitizing the GET variable that's a valid point, I'll update my answer. The ideal way would be to use whats available in the wordpress templates already, rather that using a GET param if possible. – RiaanZA Oct 11 '15 at 14:32
  • Thank you for your response. This is a nice solution but (if I am not mistaken) applies to all pages, right? In any case, I use Yoast SEO to rewrite my titles. Please let me know if you require more information. As for your existing reply, is there another place I could place it? This is because I use a child theme (Enfold) and it would be better if for example I could put it in child theme's function.php – fesarlis Oct 12 '15 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.