Link Target

Extends Drupal's Link field with a target attribute selection, allowing content editors to specify how links should open (same window, new window, etc.).

link_target
5,258 sites
20
drupal.org

Install

Drupal 11, 10, 9, 8 v8.x-1.5
composer require 'drupal/link_target:8.x-1.5'

Overview

The Link Target module enhances Drupal's core Link field by providing a widget that allows content editors to choose the target attribute for each link. This enables fine-grained control over link behavior, such as opening links in a new window or tab.

The module adds a 'Link with target' field widget that can be selected in the Form display settings for any entity type that uses Link fields. When editors create or edit content, they will see a dropdown menu allowing them to select from standard HTML target values: _self (current window), _blank (new window), _parent (parent frame), and _top (topmost frame).

Site administrators can configure which target options should be available on a per-field basis, limiting the choices presented to content editors. The selected target attribute is then rendered on the link in the frontend, providing the expected browser behavior.

Features

  • Adds a 'Select a target' dropdown to Link field forms, enabling editors to specify how links open
  • Supports all standard HTML target attribute values: _self (current window), _blank (new window/tab), _parent (parent frame), and _top (topmost frame)
  • Allows administrators to restrict available target options per field instance through widget settings
  • Seamlessly integrates with existing Link field configuration without requiring additional admin pages
  • Renders the selected target attribute directly on links in the frontend output
  • Extends Drupal's core Link widget, maintaining full compatibility with existing Link field features

Use Cases

Opening external links in new tabs

A common use case is to open external links in a new browser tab or window. By enabling the _blank target option in the widget settings and training editors to select it for external URLs, you ensure visitors don't navigate away from your site when clicking outbound links.

Single Page Applications with iframe navigation

For sites using iframes or framesets, the _parent and _top target options allow links to break out of frames and load in the parent window or topmost browsing context.

Restricting editor choices for consistency

On a corporate website where brand guidelines require all links to open in the same window, administrators can configure the widget to only show the _self option, preventing editors from inadvertently using other behaviors.

Mixed link behavior on content-heavy sites

News sites or blogs often want article links to open in the same window, but advertisement or partner links to open in new tabs. The Link Target widget gives editors the flexibility to make this choice on a per-link basis.

Tips

  • When no targets are selected in the widget settings, all four target options become available to editors
  • The target selection appears below the URL and link text fields in the content editing form
  • The _blank target is most commonly used for external links to keep users on your site
  • Consider your site's accessibility requirements when using _blank, as opening new windows can be disorienting for some users

Technical Details

Troubleshooting 3
Target dropdown not appearing on link fields

Ensure you have changed the widget type to 'Link with target' in the Form display settings for your content type. Navigate to Structure > Content types > [Your Type] > Manage form display, and change the Widget for your Link field.

Only some target options are appearing

Check the widget settings in the Form display. Click the gear icon next to the Link field to access widget settings and verify which 'Available Targets' checkboxes are selected.

Target attribute not rendered in frontend

Verify that the Link field formatter is properly configured in the Manage display settings. The target attribute is stored in the link's options and should be output by the standard Link formatter.