P
P
powercoder2019-10-28 13:24:01
PHP
powercoder, 2019-10-28 13:24:01

How to make dynamic meta tags?

There is a site in the site.ru format, there is an alias for the krd.site.ru domain. The
PHP formula sets the dynamic change of local content (city, phone numbers, maps)
How can I also make description, keywords and title dynamic meta tags?
Also, to change the city in them.
Dynamic content is implemented by PHP code, I attach.

<?php if (strpos( $_SERVER['HTTP_HOST'], 'krd.site.ru') !== false){ echo "Краснодаре"; } else { echo "Санкт-Петербурге";}
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolai Chuprik, 2019-10-28
@choupa

if (strpos( $_SERVER['HTTP_HOST'], 'krd.site.ru') !== false)
  echo "<meta name='title' content='Краснодар'>";
else
  echo "<meta name='title' content='Петербург'>";

But I wrote to you in your other question that you don’t need to do this (through if), especially if you have more than two cities. Learn to program right away.
$host = $_SERVER[ 'HTTP_HOST' ];
$city = array(
  "krd.site.ru" => "Краснодара",
  "spb.site.ru" => "Санкт-Петербурга",
  "msk.site.ru" => "Москвы",
  "urp.site.ru" => "Урюпинска",
);

echo "
  <header>
    <meta name='title' content='Лучшие индивидуалки из'".$city[ $host ].">
  </header>";

K
Kirill Gorelov, 2019-10-28
@Kirill-Gorelov

I would do it differently.
An option that would not bother much, as they say "on the knee."
I would make several files with the desired content. That is, for different cities there will be a file. And I already check the domain address condition and pull up the file I need.
The option, of course, is not ideal, but more than enough for such a simple task.
And if you want to be completely smart, then I would work through the database. Everything is the same, only it will be taken from the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question