Check URL to include metatags

Asked

Viewed 42 times

0

I need to check the url of a website, if it matches www.teste.com.br/agenda, to meta name="Description" will be "blablah", if it is www.teste.com.br/home will be "test". How do I check the URL?

  • I don’t see any difference in the 2 urls....

  • @Francis edited

  • difference in route?

  • @miltoncamara I just want that when the client accesses the page /home the Description is different from when he accesses the page /agenda

1 answer

1


Use the variable $_SERVER['REQUEST_URI'], it takes the given URI to access the current page:

if ($_SERVER['REQUEST_URI'] == "/agenda"){
    echo"<meta name='description' content='Agenda Description'>";
}
else if($_SERVER['REQUEST_URI'] == "/home"){
    echo"<meta name='description' content='Guia de Caxias do Sul'>";
}
  • Would that work too? <? if ($_SERVER['REQUEST_URI'] == "/agenda") { ? > <meta name="Description" content="Agenda Description"> <? } Else { ? > <meta name="Description" content="Southern Caxias Guide"> <? } ?>

  • I would recommend to set everything straight in php, I edited my answer, give a look.

  • I made a mistake. The site’s home has no /home, it’s just the site itself. Description is being included on the /agenda page, but ideally delete the old one.

  • If you don’t have the home, I believe $_SERVER['REQUEST_URI'] will return "/"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.