This snippet allows you to convert a WordPress tag into a hashtag that links to a tag.
It works by scanning the content for the octothorp symbol (#) and changing the word right after the # symbol to a tag-link.

Add this snippet to the functions.php file of your active theme.

function wptag_to_hashtag($mywp_post)
	$content = $mywp_post->post_content;
	$ID = $mywp_post->ID;
	preg_match_all('/\B(\#[a-zA-Z]+\b)/', $content, $matches, PREG_PATTERN_ORDER);
	if (isset($matches[1])) {
		foreach ($matches[1] as $matchKey) {
			wp_set_post_tags($ID, $matchKey, true);
add_action('post_save', 'wptag_to_hashtag', 10, 2);
function hashtagger($content)
	$siteurl = get_site_url(); // get wordpress siteurl to create url for tags
	$content = preg_replace('/([^a-zA-Z-_&])#([a-zA-Z_]+)/', "$1<a class=\"hashtags\"  href=\"$siteurl/tag/$2\" target=\"_parent\" >#$2</a>", $content);
	return $content;
add_filter('the_content', 'hashtagger');


Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

This could be the beginning of something great 🙌

"*" indicates required fields


By submitting this form: You agree to the processing of the submitted data in accordance with WP Dynamics Privacy Policy.

Contact Information
You can also write us an email or contact us by telephone.
Telephone +45 71 74 71 21

Support For support inquiries, please refer to our support section.

Recent Articles

Faust.js – A Headless Framework for WordPress

Faust.js is a Headless WordPress Framework that provides a set of tools for building front-end applications based on WordPress ...

How to Load (Enqueue) and Handle Assets and Dependencies in WordPress

In WordPress, instead of adding assets such as styles and JavaScript to the header, you can and should use ...

An Introduction to Google Tag Manager Server-side Tagging

WordPress has come a long way since its launch in 2003 - from a blogging tool to a full-fledge ...