WordPress
WordpressWordPress
Give every post a unique, on-brand OG image from one Imejis template, no page builder required. The snippet below registers a REST proxy so your API key stays on the server, then sets og:image automatically on single posts.
First define your credentials in wp-config.php.
wp-config.php
define('IMEJIS_API_KEY', 'your_api_key');
define('IMEJIS_DESIGN_ID', 'your_design_id');1 a rest proxy that renders the image1. A REST proxy that renders the image
functions.php
add_action('rest_api_init', function () {
register_rest_route('imejis/v1', '/og', [
'methods' => 'GET',
'callback' => 'imejis_render_og',
'permission_callback' => '__return_true',
]);
});
function imejis_render_og($request) {
$title = sanitize_text_field($request->get_param('title') ?: 'Untitled');
$response = wp_remote_post('https://render.imejis.io/v1/' . IMEJIS_DESIGN_ID, [
'headers' => [
'dma-api-key' => IMEJIS_API_KEY,
'Content-Type' => 'application/json',
],
'body' => wp_json_encode(['headline.text' => $title]),
'timeout' => 20,
]);
header('Content-Type: image/jpeg');
header('Cache-Control: public, immutable, no-transform, max-age=31536000');
echo wp_remote_retrieve_body($response);
exit;
}2 set ogimage on every single post2. Set og:image on every single post
functions.php
add_action('wp_head', function () {
if (! is_singular()) {
return;
}
$url = home_url('/wp-json/imejis/v1/og?title=' . rawurlencode(get_the_title()));
printf('<meta property="og:image" content="%s" />' . "\n", esc_url($url));
echo '<meta name="twitter:card" content="summary_large_image" />' . "\n";
});Override any field. Each dynamic component exposes keys like headline.text, title.color, or image.image. Send only the ones you want to change, and add more query params as needed. A design's overridable fields are listed in its Share / API panel.