Dynamic Generation of Shop Pages with Open Graph Meta Tags in PHP

 To display the correct image when sharing a link for each shop in a `shop.php` page, you can dynamically generate Open Graph meta tags for each shop. This involves extracting shop-specific information from your database or wherever it's stored. Here's an example of how you can do this using PHP:


Assuming you have a PHP array or some mechanism to store your shop data:


```php

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Shop Page</title>

</head>

<body>


<?php

  // Assuming $shops is an array with shop data

  $shops = array(

    array(

      'name' => 'Shop 1',

      'description' => 'Description for Shop 1',

      'image' => 'path/to/shop1.jpg',

      'url' => 'http://example.com/shop1'

    ),

    array(

      'name' => 'Shop 2',

      'description' => 'Description for Shop 2',

      'image' => 'path/to/shop2.jpg',

      'url' => 'http://example.com/shop2'

    ),

    // Add more shop entries as needed

  );


  foreach ($shops as $shop) {

    echo '<div>';

    echo '<h2>' . $shop['name'] . '</h2>';

    echo '<p>' . $shop['description'] . '</p>';

    echo '<a href="' . $shop['url'] . '">Visit Shop</a>';

    echo '</div>';


    // Open Graph meta tags for each shop

    echo '<meta property="og:title" content="' . $shop['name'] . '">';

    echo '<meta property="og:description" content="' . $shop['description'] . '">';

    echo '<meta property="og:image" content="' . $shop['image'] . '">';

    echo '<meta property="og:url" content="' . $shop['url'] . '">';

  }

?>


</body>

</html>

```


This example assumes that you have an array `$shops` containing information about each shop. The PHP code dynamically generates HTML for each shop along with Open Graph meta tags. Make sure to replace the placeholder values in the `$shops` array with your actual data.


When someone shares a link to a specific shop, the associated image and information will be used in the link preview on platforms like WhatsApp.

Previous
Next Post »