Skip to content

OG Gallery Custom Links

OG Gallery Custom Links adds link fields to every image in your Media Library. Set a link once, and that image goes there every time it appears in a gallery.

Requires: WordPress 6.0+ and PHP 8.1+. Product page: OG Gallery Custom Links.

Who it's for

Photographers, agencies, shop owners and bloggers who want gallery images to lead to products, articles, portfolios or partner pages, without rebuilding their galleries.

It works with the standard WordPress gallery, the block editor (Gutenberg) gallery and OG Gallery. Other galleries work too when their images keep the standard WordPress wp-image-ID class, or when their wrapper class is added with a filter (see the developer's guide).

Install and activate

  1. Download the zip from My Account > Licences on og-nexus.com.
  2. Upload it in Plugins > Add New > Upload Plugin, then activate it.
  3. Paste your licence key in the plugin's licence tab.

The full steps are in Install and activate a plugin.

What the licence adds

The link fields, the parsing engines, buttons and all settings work as soon as the plugin is active. The OG Gallery Custom Links column in the Media Library, the Unlinked filter and Per Page Linkage need an active licence. They are downloaded to your site after you activate the key.

Where to find it

  • Settings: in the WordPress menu, open OG AI Core (or OG Nexus when OG AI Core is not installed), then Media > Gallery Links. The screen address is wp-admin/admin.php?page=oggcl_settings.
  • Link fields: open any image in Media > Library. The fields sit with the other attachment details.
  • Links column (needs a licence): Media > Library in list view.

Settings

The settings screen has two cards, Settings and Buttons. Changes save as soon as you make them. The default settings suit most sites.

Settings

Setting What it does Default
Parsing Engine How the plugin adds the links to your pages. See the table below. HtmlDomParser
OB Mode When Enabled, the plugin reads the whole page, so linked images in the header, footer or sidebar work too. When off, only the main post content is read. It slows each page down a little, so use a page cache. Enabled
Skip on Current Page When Enabled, a custom link that points to the page the visitor is already on is ignored. The lightbox then opens as normal instead of reloading the same page. Off
Logs Simple logging, written to the PHP error log. Switch it on only while you look into a problem. Off

The parsing engines:

Engine How it works Use it when
HtmlDomParser Rewrites the page HTML, so the links are part of the page. Very reliable. Almost always. It is the default.
DiDom Same as HtmlDomParser, but faster. Your HTML must be valid. Pages are very large, or HtmlDomParser can't read them.
Javascript The page HTML is left alone. The visitor's browser adds the links after the page loads. Fastest. Speed matters more than search engines seeing the links.
None (Not Supported Yet) Adds no links on the front end. Not recommended.

Search engines

If you want search engines to see the links, use HtmlDomParser or DiDom. With Javascript, the links are not in the HTML your server sends.

Buttons

Setting What it does Default
Use Buttons When Enabled, linked images get a small call-to-action button that carries the link. Off
Label The text on the button. Click here

Buttons work with OG Gallery and block editor galleries. With the DiDom engine, buttons are not added; use HtmlDomParser or Javascript.

Open an image in the Media Library to see these fields:

Field What it does
Link URL Where the image links to. As soon as this is filled in, the image links there in every gallery it is used in. Leave it empty to keep the normal behaviour.
Link Target Same page opens the link in the same tab. New page opens it in a new tab.
Link Rel The rel value of the link, such as nofollow, sponsored or noopener noreferrer.
ARIA Label The ARIA label of the link. Screen readers read it out, so say where the link goes.

Linked images skip the lightbox, so the click goes straight to your link.

In Media > Library list view, a column called OG Gallery Custom Links shows a link icon for each image. Click it to open Edit the custom link. It has the same four fields as above, plus Per Page Linkage.

Per Page Linkage changes the link depending on the page being viewed. Each row has a Page URL and a Target URL. When the visitor is on the Page URL, the image links to the Target URL instead of its normal Link URL. Click Add for a new row, or the bin icon to remove one.

Page addresses are matched without http:///https://, www., a trailing slash, a query string or a # anchor. You can enter a full address or just the path, such as /shop/.

The list view also gets an Unlinked option in the media type filter. It shows the images that have no Link URL yet.

This column is shown to administrators only.

Common tasks

  1. Go to Media > Library and open the image.
  2. Fill in Link URL with the full address.
  3. Pick a Link Target, and add an ARIA Label that says where the link goes.
  4. In the media window, the fields save when you click out of them. On the full Edit Media screen, click Update.
  5. View a page with a gallery that uses the image, and click it to check.
  1. Open the image in the Media Library.
  2. Set Link Rel to sponsored (paid) or nofollow (partner).
  3. Check the link on the front end.
  1. Open Gallery Links settings.
  2. Switch OB Mode to Enabled.
  3. Clear your page cache, then check the page.

Show a button instead of a clickable image

  1. Open Gallery Links settings and go to the Buttons card.
  2. Switch Use Buttons to Enabled.
  3. Type your button text in Label.
  4. Make sure Parsing Engine is HtmlDomParser or Javascript.

Send one image to different pages (needs a licence)

  1. Go to Media > Library in list view.
  2. Click the link icon in the OG Gallery Custom Links column.
  3. Under Per Page Linkage, click Add.
  4. Enter the page the gallery is on in Page URL, and where the image should go from that page in Target URL.
  5. Click OK.
  1. Go to Media > Library in list view.
  2. Pick Unlinked in the media type filter and click Filter.

FAQ and troubleshooting

How do I check what the plugin did on a page?

Open the page and view its source. Near the end, just before </body>, you'll see a line like this:

<!-- OG Gallery Custom Links: 12 images scanned, 3 linked (HtmlDomParser). -->

If the line says the engine "could not parse this page", read the next answer. If OB Mode is off, another comment says only the main content was read. With Javascript, a comment says the links are added by the browser.

The plugin does nothing on a very large page

HtmlDomParser can't read pages over about 600 KB of HTML. The source comment then says the page is over the limit. Switch Parsing Engine to DiDom.

Images outside the post content are not linked

Switch on OB Mode. Without it, only the main content is read.

The lightbox still opens

Linked images get the no-lightbox class, and the plugin stops other click handlers on them. If a lightbox still opens, clear your page cache and check the page source report. If no images were linked, the image could not be matched to its Media Library entry.

Why is my image not linked?

The plugin finds each image's Media Library entry from its attachment ID, its wp-image-ID class, or its file address. Check that:

  • the image comes from your Media Library, not an outside address;
  • Link URL is filled in;
  • Skip on Current Page is not hiding a link to the same page;
  • your gallery is supported. For other galleries, a developer can add the gallery's class with a filter.

Yes. With HtmlDomParser or DiDom, the links are in the cached HTML. Clear the cache after you change a link.

Uninstalling

Deactivating or deleting the plugin stops the links on your pages. The plugin has no clean-up routine, so its settings and the link fields saved on your images stay in the database. If you install it again, your links come back.

For developers

Hooks, REST routes, meta keys and options are in the developer's guide.