# Link Widget Titles to a Page

> Adds a "Title link" field to every classic widget, turning its title into a link, for example from "Latest News" to your news page.

- Type: PHP
- Runs: Run everywhere
- Category: [Widgets](https://wpide.com/library/category/widgets/)
- Tags: widgets, titles, links
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/widget-title-links/

## Code

```php
add_action( 'in_widget_form', function ( $widget, $return, $instance ) {
    $id = $widget->get_field_id( 'wpide_title_link' );

    echo '<p><label for="' . esc_attr( $id ) . '">Title link (optional):</label> <input type="url" class="widefat" id="' . esc_attr( $id ) . '" name="' . esc_attr( $widget->get_field_name( 'wpide_title_link' ) ) . '" value="' . esc_attr( isset( $instance['wpide_title_link'] ) ? $instance['wpide_title_link'] : '' ) . '" placeholder="https://" /></p>';
}, 10, 3 );

add_filter( 'widget_update_callback', function ( $instance, $new_instance ) {
    $instance['wpide_title_link'] = isset( $new_instance['wpide_title_link'] ) ? esc_url_raw( trim( $new_instance['wpide_title_link'] ) ) : '';

    return $instance;
}, 10, 2 );

add_filter( 'widget_title', function ( $title, $instance = array() ) {
    if ( is_admin() || '' === (string) $title || empty( $instance['wpide_title_link'] ) ) {
        return $title;
    }

    return '<a href="' . esc_url( $instance['wpide_title_link'] ) . '">' . $title . '</a>';
}, 20, 2 );
```

## Notes

Core widgets show the link; third-party widgets that escape their own titles may show the title as plain text.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Link Widget Titles to a Page" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
