🔍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:
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