passing meta data in body part

孤者浪人 提交于 2019-12-24 16:15:44

问题


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.


回答1:


<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.




回答2:


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.




回答3:


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.




回答4:


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();

?>



回答5:


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



来源:https://stackoverflow.com/questions/3126926/passing-meta-data-in-body-part

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!