Render dynamic og images in PHP
{{variable}}
syntax to enable them to be replaced with custom data.
For more information, visit our guide on dynamic images with variables.
Template example, dynamic variables are marked with {{}}
{{title}}
, and the image URL is represented by {{image}}
. By default, the template will render with the static data unless you specify the dynamic values.
Example of the image generation URL
TEMPLATE_ID
with the actual ID of your template, and provide values for the variables via query parameters.
For example:
og:image
meta tag for Open Graph integration, which is commonly used in social media sharing.
For dynamic data, make use of PHP’s urlencode()
function to safely encode the values.
Here is an example of how you can add the dynamic og:image tag to your PHP application:
$pageTitle
and $imageURL
are PHP variables that contain the title and image URL, respectively. You can place this code inside the head section of your HTML output, dynamically generating og tags for each page.
You can place this code inside the head section of your HTML output, dynamically generating og
tags for each page.
Now, when your page is shared on social media, the dynamically generated image will be displayed using the title and image URL provided in the PHP variables.
You can see the image generated dynamically:
The image generated dynamically in PHP