Skip to Content

Add hashtags to Elementor tags

Elementor
February 22, 2024 by
Add hashtags to Elementor tags
JZ Web

In Wordpress, keywords (tags) are an important way to categorize and organize content. You often want to add hashtags to these tags to better identify them on social media. However, Wordpress adds commas between the tags by default, which makes it difficult to use them directly as hashtags. If you are an Elementor page builder user, you can solve this problem elegantly.

Step 1: Add the keywords in Wordpress


It is best to edit the individual post page in Elementor. You can find it here:

Dashboard -> Templates -> Theme Builder -> Elementor Single Post


Now add the block: Edit Post Info in the template and use Terms


Step 2: Add hashtags before keywords


Add an HTML block to the post page:

In principle, however, you can insert this anywhere on the template page.In the example, the HTML block is placed directly below the keywords.

WordPress post tags shown with commas below an empty HTML block in Elementor

Elementor HTML widget placed directly below the post tags


Fill the HTML block with the following code:

<script>document.addEventListener('DOMContentLoaded', function() {const tagsContainer = document.querySelector('.elementor-widget-wp-widget-tag_cloud'); if (tagsContainer) {const tags = tagsContainer.querySelectorAll('a');tags.forEach(function(tag) {const text = tag.textContent;const newText = '#' + text; tag.textContent = newText; if (tag.nextSibling && tag.nextSibling.nodeType === Node.TEXT_NODE && tag.nextSibling.textContent.trim() === ',') {tag.parentNode.removeChild(tag.nextSibling);}});}); </script>


JavaScript snippet that adds a hash sign to each tag and removes the commas


Step 3: Save and check


Save your changes and check your page or post. The keywords should now have hashtags and the commas should be removed.

Conclusion

By adding hashtags to the keywords in Wordpress and removing the commas using JavaScript in Elementor, you can ensure that your content is more recognizable on social media and has an appealing appearance. This method is easy to implement and offers an effective way to improve your content.


Result: WordPress tags displayed as hashtags without commas



Your Website, Free for 30 Days: Try Tagfalter with the Code JZWEB
A ready-made website for small businesses and clubs, securely hosted in Tyrol. With JZWEB you test it for 30 days instead of 7.