share-cards is a WordPress plugin that supplies the og:image and twitter:image for posts, categories, tags and custom pages. It is for news and publishing sites that want a proper preview image on every shared link. It is MIT licensed, and v0.1.0 was released on 14 November 2026.
Social platforms show a large preview image when a link is shared, taken from og:image and twitter:image. A news site without a card generator has three poor options. It can use the featured image as it is, but many featured images are too small or the wrong shape, and platforms crop them badly or fall back to a small thumbnail. It can use one placeholder for every archive and every image-less post, so every shared category and tag page looks the same. Or it can render a card for every post at publish time, which spends CPU and disk on images for posts nobody shares.
The plugin renders a card only when a scraper or browser first asks for it, stores it outside the media library, and serves the file after that.
examples/.warm, status, render, url, gc and flush.The plugin decides what to advertise once per page view, without reading any image file. A card URL looks like /share-card/post-42-3f9a1c0b7e.jpg. The last part is the first 10 hex characters of a SHA-256 over everything drawn on the card: headline, kicker, footnote, backdrop file, settings, renderer and template version. Change any of those and the URL changes, which is why a CDN can cache cards for a year.
The endpoint runs on parse_request, before the main query and the theme. A current card is streamed with X-Share-Card: hit. A stale hash gets a 302 to the current URL. On a cold cache one process takes a file lock for the key and renders. Others wait up to lock_wait_ms, then get a 302 to the featured or default image. The card is written to a temporary name and renamed into place, so no reader sees half a file.
Layout (wrapping, the size ladder, ellipsis) is computed once in plain PHP. GD or Imagick only measures, draws and encodes. The backdrop is cover-cropped around a focal point, darkened, and covered with the background colour. Output is a progressive JPEG with no metadata. Fonts are not bundled: the plugin finds Noto Sans or DejaVu Sans, and scripts that need shaping are drawn only through Imagick with Pango.
Edits delete a post’s old card variants at once and fire share_cards_purged with their URLs. The plugin never calls a CDN itself. Themes can ask for the final image:
share_cards_image_for_request(): ?array // url, width, height, type, alt, source (card, featured, default)
Files go in one cache directory, by default under the uploads folder. There are no attachment rows and no post meta.
max_concurrent renders run at once (default 2) and at most renders_per_minute start each minute (default 30). Past either limit the request gets the fallback image and the header says why.failure_ttl seconds (default 600). The cache has a disk cap (default 512 MB) and a daily clean-up.manage_options and a nonce. There is no shell call and no eval.pango: coder runs text through its own property interpreter before Pango sees it. A headline containing %m was drawn as “PANGO” and %[fx:1+1] was evaluated. Every % and \ is now doubled before the read, with a test that fails without the change.admin_init, which also fires for admin-ajax.php, so a visitor could trigger it. It now needs manage_options.share_cards_backdrop_path.LockProvider.This is v0.1.0. The review reports 173 PHPUnit tests, PHPStan level 8 and phpcs clean on a local PHP 8.3, using stubs and mocks of WordPress. PHP 8.1 and 8.2 have been checked only statically, CI has not yet run on GitHub, and the plugin has not run on a live site. It was specified, built and reviewed in separate roles by language-model coding agents under the editor’s direction.
It needs PHP 8.1, 8.2 or 8.3 with ext-mbstring, WordPress 6.4 or later, and either ext-gd with JPEG and FreeType or ext-imagick that can write JPEG. You need at least one TrueType or OpenType font.
The package is not on Packagist yet, so first add a Composer vcs repository entry for https://github.com/IndianOpinion/share-cards.
composer require indianopinion/share-cards