Hacker
Hacker

Reputation: 7906

passing meta data in body part

I use php for coding. Is there a way to pass meta in the body part. so that it is recognized by search engines. I know meta tags needs to be passed in head. but since i am generating pages dynamically . Only body part get changed in every page.

Upvotes: 1

Views: 2322

Answers (5)

renoirb
renoirb

Reputation: 559

How about using a templating library such as Twig. Create blocks and extend pages and override block with more specific content.

Upvotes: 0

GOsha
GOsha

Reputation: 689

You can use output buffering and renew meta-data using placeholders after generating page.
Like this:

<?php

function callback($buffer) {

  return (ereg_replace("meta", "<META blah-bla-bla />....", $buffer));

}

ob_start("callback");

?>

<html>
<head>meta</head>
<body>
<p>It's like comparing apples to oranges.
</body>
</html>

<?php

ob_end_flush();

?>

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382666

You should go with specification, it shouldn't be that difficult to even generate the meta tags dynamically like you are doing for the body part.

You can also use the Simple HTML DOM to manipulate the html at any part of the page.

Upvotes: 1

Yuval Adam
Yuval Adam

Reputation: 165212

<meta> tags must go in the <head> - per the HTML specification.

Refactor your templates so you will be able to add <meta> tags dynamically in the head. It shouldn't be a problem.

Upvotes: 2

Oded
Oded

Reputation: 498932

The html specs specify that meta tags belong in the head section of an HTML document.

You can generate the meta tags dynamically as well, just add them in the head section that you are outputting.

A php template will have head sections as well as body sections - just change them to output dynamic meta tags.

Upvotes: 2

Related Questions