Search code examples
phpmarkuprich-snippets

How to do rich snippet markup in php?


My problem is that the webpage that I do is in complete PHP files. Everywhere there is tutorial how to generate, but there is no instructions what to do when it is a PHP file.

The main file is also index.php. When I insert the code that is generated in HTML.

Comes with a lot of errors, so I convert it to PHP.

it will start like

echo "..bla bla" "\n" ;

echo "<div property=\"gr:legalName\" content=\"G &amp; Sziladi\"></div>\n"; 

which is good already, google recognize it, BUT this will show on the top of my page.How can i insert this markup into index.php without showing,but also google has to recognize it properly.


Solution

  • If you prefer to copy and paste HTML, the paste it into a PHP file but outside of the PHP tags:

    <?php
    /*
     * May brand new PHP Website 
     */
    
    $title_prefix = '- Escaping the Tags';
    
    ?>
    <html>
      <head>
        <title>Supersite Deluxe <?php echo $title_prefix; ?></title>
      </head>
      <body>
       ....
      </body>
    </html>
    

    That is especially useful if you have to a lot of HTML, because you can just paste it in.

    See Escaping from HTML