# Hashtags From Tags in Feed Items

> Turns each post's tags into hashtags such as #HomeOffice at the end of the feed summary, so RSS-to-social tools like Buffer, Zapier or IFTTT post them automatically.

- Type: PHP
- Runs: Run everywhere
- Category: [RSS Feeds](https://wpide.com/library/category/rss/)
- Tags: feeds, hashtags, social
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/hashtags-from-tags-in-feeds/

## Code

```php
// Where the hashtags go: 'description' (the summary most RSS-to-social tools post) or 'both' to add them to the full content too.
$wpide_feed_hashtags_in = 'description';
// Maximum number of hashtags per item.
$wpide_feed_hashtags_max = 4;

$wpide_feed_hashtags = function () use ( $wpide_feed_hashtags_max ) {
    $tags = get_the_tags();

    if ( ! $tags || is_wp_error( $tags ) ) {
        return '';
    }

    $out = array();

    foreach ( array_slice( $tags, 0, max( 1, (int) $wpide_feed_hashtags_max ) ) as $tag ) {
        // "Home office" becomes #HomeOffice; accents and other alphabets are kept.
        $words = preg_split( '/[^\p{L}\p{N}]+/u', $tag->name, -1, PREG_SPLIT_NO_EMPTY );
        $words = array_map( function ( $word ) {
            return function_exists( 'mb_strtoupper' ) ? mb_strtoupper( mb_substr( $word, 0, 1 ) ) . mb_substr( $word, 1 ) : ucfirst( $word );
        }, (array) $words );

        if ( $words ) {
            $out[] = '#' . implode( '', $words );
        }
    }

    return implode( ' ', array_unique( $out ) );
};

add_filter( 'the_excerpt_rss', function ( $excerpt ) use ( $wpide_feed_hashtags ) {
    $tags = $wpide_feed_hashtags();

    return '' === $tags ? $excerpt : $excerpt . ' ' . esc_html( $tags );
} );

if ( 'both' === $wpide_feed_hashtags_in ) {
    add_filter( 'the_content_feed', function ( $content ) use ( $wpide_feed_hashtags ) {
        $tags = $wpide_feed_hashtags();

        return '' === $tags ? $content : $content . '<p>' . esc_html( $tags ) . '</p>';
    } );
}
```

## Notes

Set the place to 'both' to add the hashtags to the full content as well; the number of hashtags is capped at four by default.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Hashtags From Tags in Feed Items" 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/
