Echo in HTML meta tag

Is it possible to have a PHP echo statement inside of an HTML meta tag?

I would like to mix text and a pre-defined constant in the content attribute…

<meta name="description" content="">

PHP inside anything is possible. Not really, but yes. You can have a constant inside of the content attribute.

So could I do this…

<meta name="description" content="At the <?php echo COMPANY_NAME; ?>, customer service is very...">

Yup. That’s possible.

But is it desirable? :wink:

Depends if you want to change it later or have it stay like that for a long time. If you want to change it later, I would say use PHP to generate the text. This would make it really easy on you because let’s say you are using the same meta on 50 different pages. Do you really want to go through all 50 pages manually and change them? Or do you want to change a constant and let the text change within all 50 pages?

Well, I might reuse this code for another client, so I would like to do this so I don’t forget to update things and have a meta tag for John’s Deli on Sam’s Subs website! :smile:

Then yeah. I’d say go for it. If you are going to be using a constant, you can always change the text on it.

@spaceshiptrooper,

Thanks!

Yes, let the server do the donkey work. How do you think database driven sites with 100s or 1000s of pages work?
Does someone sit typing out all those pages by hand, or is there a php script that pulls the info from a database and fills in the blanks?

1 Like

Okay, thanks!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.