Search by

faithcatholic / custom_metatags

nketchummjones

Allows users to tweak metatags.

Package info

github.com/FaithCatholic/custom_metatags

Language:Shell

Type:drupal-module

pkg:composer/faithcatholic/custom_metatags

Statistics

Installs: 1 374

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v4.0.0 2026-09-10 00:48 UTC

This package is auto-updated.

Last update: 2026-09-11 22:22:34 UTC


README

Gives a site one fallback image for Open Graph sharing. The module adds a Metatag tag called "Default image", og:image:default, that you fill in once in the Metatag defaults. On every non-admin page it then looks at the tags the page is about to render. If the page has no og:image of its own, the default is rewritten as og:image so social networks pick it up. If the page already has one, the default is dropped, so a page never emits two og:image tags.

Note the naming: the repository directory and the Composer package are custom_metatags, with an s, while the module machine name is custom_metatag, without one. Use custom_metatag for drush en, namespaces and service ids.

Requirements

  • Drupal 10.3 or newer, or Drupal 11.
  • Metatag, with its Metatag: Open Graph submodule (metatag_open_graph) enabled. That submodule provides the Open Graph group the new tag joins, and the module will not install without it.

The module does nothing until the tag has a value. It expects a Metatag defaults record, normally Global, with "Default image" filled in. It also waits for the metatag_defaults entity type to exist before doing anything, so during an upgrade it stays inert until database updates have run.

Installation

Install at /admin/extend, or run drush en custom_metatag.

If nothing changes after installing, the tag has not been set yet. See Usage.

Usage

  • Go to /admin/config/search/metatag, edit a defaults record, usually Global, and set "Default image" in the Open Graph group. It takes the same token and image value as the regular Open Graph "Image" tag.
  • Leave the regular "Image" tag empty at that level. If it has a value, every page already has an og:image and the default is never used.
  • Per-page and per-bundle og:image values still win. The default only fills the gap.
  • Admin pages are skipped.
  • There are no routes, no permissions and no settings form of its own. Editing the tag needs Metatag's "administer meta tags" permission.

Development

The repository carries a DDEV setup that builds a throwaway Drupal site around the module.

  • ddev start runs .ddev/post-start.sh, which fetches the dev dependencies with poser, installs the site if the database is empty, enables devel, metatag, metatag_open_graph and custom_metatag, and prints a one-time login link. The account is admin with password 1.
  • The module is symlinked into web/modules/custom/custom_metatags. Both web/ and vendor/ are ignored by git.
  • ddev phpcs and ddev phpcbf for coding standards.
  • ddev phpstan --level=6 -c ../../../../phpstan.neon for static analysis. Pass the config explicitly. Plain ddev phpstan runs without it and reports nothing useful, because the add-on symlinks phpstan.neon into the module directory with a relative path that does not resolve, which silently drops the run to level 0 and skips the project ignores. The relative path above is correct because the wrapper changes into the module directory first.
  • Add-ons in use: ddev-drupal-contrib, ddev-drupal-contrib-extras, ddev-drupal and pimp-my-shell.

Notes

  • OgImageDefault still declares itself with the @MetatagTag annotation rather than a PHP attribute. Metatag 2.x still reads annotations, but they are being phased out and this needs converting before Drupal 12.
  • custom_metatag_preprocess_html() in custom_metatag.module is a stub that exists only for Drupal 10, which cannot find hooks declared with attributes. It is marked #[LegacyHook], so Drupal 11 ignores it and runs CustomMetatagHooks::preprocessHtml() instead. Once the supported floor is Drupal 11.1 the stub, the .module file and the services.yml entry can all go, because Drupal 11 auto-registers classes in src/Hook.