Can I use PHP to create dynamic meta tags for SEO?

Asked

Viewed 2,288 times

2

I wonder if it is possible to use PHP in metatags, like Description, Keywords...

I already use the title: <title><?php echo $titulo; ?>. I can do the same for metatags?

Of:

<meta name="DESCRIPTION" content="descrição aqui, etc, etc...">

To:

<meta name="DESCRIPTION" content="<?php echo $descricao; ?>">
  • Yes, you can. You’ve tried? ;)

  • No, because I was afraid something went wrong. My idea is the same as <title><? php echo $title; ? ></title> On each page I will define the variables $Description and $Keywords, and la in the header will fetch this variable. So each page will have its own, right? I don’t know if I’m right, but it takes a few days for google to print these new values in its results, right?

  • The nice thing is to install Xamp or similar on your machine, so you can run php locally to test the will

  • 1

    I already use Wamp! I believe that this time I spoke nonsense... just I test the variables in the metatag and display the source code of each page to know if it is changing, right?! What a wobble! rs

  • yes, exactly

  • Being able to do this can, but you have to know if Google and other browsers will actually take into account the content you have in these variables.

Show 1 more comment

2 answers

2


Answer

You can use yes.

But why?

Both Google and any other search engine or browser will understand the data the same way you would if you set the values directly in HTML.

This is basic PHP concept.

PHP is a server-side language, meaning it runs on the server side. So, before any HTML information is sent to anyone, it will be processed by the PHP module, which will generate a complete HTML and only then send to the visitor / requester.

Don’t get it yet?

Let’s illustrate.

  1. The visitor accesses your domain and requests the index.php file (or any other);

Your original index.php file looks like this

<?php
    $descricao = 'informatica, hospedagem, criação de sites, cloud';
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="utf-8">
    <title>Meu site - Menino sagaz</title>
    <meta name="description" <?php echo "content='" . $descricao . "'"; ?>>
</head>
<body>
    <h1>Olá, mundo!</h1>
</body>
</html>
  1. Your server will receive the request and is a file. php, will trigger the PHP module to interpret any and all PHP code in the file.

Then the PHP module does its job and turns your index.php file into this

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="utf-8">
    <title>Meu site - Menino sagaz</title>
    <meta name="description" content='informatica, hospedagem, criação de sites, cloud'>
</head>
<body>
    <h1>Olá, mundo!</h1>
</body>
</html>
  1. With the file ready, it sends the index.php to the visitor and everyone is happy.

PS: visitor can be anyone, be the visitor (ôh), Google, Bing and even Yahoo.

In short

It doesn’t matter if you made your site 100% using echo to generate HTML’s and content. The visitor will NEVER know how it was done, because he will always receive the ready file, already processed by the PHP module.

1

PHP as a back-end language will deliver the already rendered page to your users and search engines. Resulting in the same content that you would manually play.

Browser other questions tagged

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