🔍SEO
PressGang includes a built-in MetaDescriptionService that generates smart, cached meta descriptions for every page on your site. No need for a full SEO plugin just to get decent meta tags — PressGang has you covered on this voyage.
MetaDescriptionService
The MetaDescriptionService generates a single, authoritative meta description for the current page. It's available in Twig via the meta_description() function (registered by the MetaDescriptionExtensionManager).
Usage in Twig
{{ fn('wp_head') }}That's it. PressGang's SEO service provider renders its fallback <meta name="description"> tag through wp_head only when a dedicated SEO plugin is not detected.
Fallback Chain
The service uses a smart fallback chain to find the best description for each page type:
Posts and Pages
Yoast SEO meta description (
_yoast_wpseo_metadescpost meta) — if Yoast is installed and a description is set, it takes priority.Custom field (
meta_descriptionpost meta) — a manual override without needing Yoast.Post excerpt — the WordPress excerpt field.
Post content — falls back to the rendered content.
Site tagline — the default site description from Settings > General.
Taxonomy Terms
Yoast SEO taxonomy meta — if configured in Yoast's taxonomy settings.
Term description — the description field from the term editor.
Site tagline — the default fallback.
Archives
Archive description — via
get_the_archive_description().Site tagline — the default fallback.
Truncation
Descriptions are automatically truncated to 155 characters (the recommended SEO limit) using smart boundary detection:
If the description fits within 155 characters, it's used as-is.
If it's longer, PressGang looks for the last full stop (period) within the limit and cuts there.
If no sentence boundary is found, it trims to the last complete word.
This ensures descriptions always read naturally — no awkward mid-word cutoffs.
Caching
Meta descriptions are cached per object using wp_cache, so the fallback chain only runs once per page per request cycle. The cache key is based on the object type and ID.
Hooks
pressgang_contact_to_email
filter
ContactSubmission
The MetaDescriptionService can read Yoast SEO data when generating fallback descriptions, but PressGang does not output its own meta description tag when Yoast SEO, Rank Math, or All in One SEO is detected. This avoids duplicate description tags while keeping the fallback service useful for themes without a dedicated SEO plugin.
SEO Plugin Detection
PressGang checks common SEO plugin constants before rendering its fallback meta description:
WPSEO_VERSIONfor Yoast SEO.RANK_MATH_VERSIONfor Rank Math.AIOSEO_VERSIONfor All in One SEO.
The detection and rendering decision are filterable:
Configuration
The SeoServiceProvider is registered by default in config/service-providers.php. The MetaDescriptionExtensionManager is also registered by default in config/twig-extensions.php for themes that want to call {{ meta_description() }} directly.
To add meta_description() support to a theme, ensure the extension manager is listed:
Last updated