# Social Profiles Widget

> Adds a "Social Profiles" widget with links to your profiles on Facebook, Instagram, X, LinkedIn, YouTube, TikTok, Bluesky, Mastodon and more, as an accessible list of text links.

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

## Code

```php
if ( ! class_exists( 'WPIDE_Social_Profiles_Widget' ) ) {
    class WPIDE_Social_Profiles_Widget extends WP_Widget {
        // Networks offered in the widget form, in display order.
        const NETWORKS = array(
            'facebook'  => 'Facebook',
            'instagram' => 'Instagram',
            'x'         => 'X',
            'linkedin'  => 'LinkedIn',
            'youtube'   => 'YouTube',
            'tiktok'    => 'TikTok',
            'pinterest' => 'Pinterest',
            'bluesky'   => 'Bluesky',
            'mastodon'  => 'Mastodon',
            'threads'   => 'Threads',
            'github'    => 'GitHub',
        );

        public function __construct() {
            parent::__construct( 'wpide_social_profiles', 'Social Profiles', array(
                'description'                 => 'Links to your profiles on social networks.',
                'customize_selective_refresh' => true,
            ) );
        }

        public function widget( $args, $instance ) {
            $links = array();

            foreach ( self::NETWORKS as $key => $label ) {
                if ( ! empty( $instance[ $key ] ) ) {
                    // rel="me" lets Mastodon and similar services verify the link back to your site.
                    $links[] = '<li><a href="' . esc_url( $instance[ $key ] ) . '" rel="me noopener" target="_blank">' . esc_html( $label ) . '<span class="screen-reader-text"> (opens in a new tab)</span></a></li>';
                }
            }

            if ( ! $links ) {
                return;
            }

            $title = isset( $instance['title'] ) ? $instance['title'] : 'Follow Us';
            $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );

            echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput -- theme markup.

            if ( '' !== (string) $title ) {
                echo $args['before_title'] . esc_html( $title ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput
            }

            echo '<ul class="wpide-social-profiles" style="display:flex;flex-wrap:wrap;gap:.5em;list-style:none;margin:0;padding:0;">' . implode( '', $links ) . '</ul>'; // phpcs:ignore WordPress.Security.EscapeOutput -- escaped above.
            echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput
        }

        public function form( $instance ) {
            $title = isset( $instance['title'] ) ? $instance['title'] : 'Follow Us';

            echo '<p><label for="' . esc_attr( $this->get_field_id( 'title' ) ) . '">Title:</label><input class="widefat" type="text" id="' . esc_attr( $this->get_field_id( 'title' ) ) . '" name="' . esc_attr( $this->get_field_name( 'title' ) ) . '" value="' . esc_attr( $title ) . '" /></p>';

            foreach ( self::NETWORKS as $key => $label ) {
                echo '<p><label for="' . esc_attr( $this->get_field_id( $key ) ) . '">' . esc_html( $label ) . ' URL:</label><input class="widefat" type="url" id="' . esc_attr( $this->get_field_id( $key ) ) . '" name="' . esc_attr( $this->get_field_name( $key ) ) . '" value="' . esc_attr( isset( $instance[ $key ] ) ? $instance[ $key ] : '' ) . '" /></p>';
            }

            return '';
        }

        public function update( $new_instance, $old_instance ) {
            $clean = array( 'title' => isset( $new_instance['title'] ) ? sanitize_text_field( $new_instance['title'] ) : '' );

            foreach ( array_keys( self::NETWORKS ) as $key ) {
                $clean[ $key ] = isset( $new_instance[ $key ] ) ? esc_url_raw( trim( $new_instance[ $key ] ), array( 'https', 'http' ) ) : '';
            }

            return $clean;
        }
    }
}

add_action( 'widgets_init', function () {
    register_widget( 'WPIDE_Social_Profiles_Widget' );
} );
```

## Notes

Leave a network empty to hide it; links carry rel="me" so Mastodon can verify your site.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Social Profiles Widget" 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/
