Linkify words in post


(Sam Saffron) #1


Theme component, this component can be included in your current theme.


How to Install

What this does?

Allows you to automatically hyperlink certain words or patterns in your post with desired destination URL.

How to configure?

After importing the theme component, configure the theme settings with the format


or using regular expressions (in JavaScript implementation) with the format


One item per line

Using regular expressions

With regular expressions, you can match a certain pattern to a single URL. This is useful for synonyms or for words which can take different forms in the sentence etc.

However, you can also generate the URL automatically based on what was matched. For example, let’s say you have a line of products, each with its own numeric id, and you want to autolink them to their own URLs. Using


product-42 will be autolinked to
Notice the capturing parentheses in the regular expression and the $1 in the URL which is substituted by the match inside the parenthesis. You can also capture multiple parts of the string and use $2, $3 and so on.

Regular expressions are by default case sensitive (unlike WORD’s which are case insensitive). However, you can change that by using a standard “i” modfier like this:


In this case, FOO, Foo or foo will all be matched.


  1. Replacement will only appear in the web UI and will not appear in emails.

  2. Requires Discourse 2.0.0.beta3 +267 or later.

How this looks in action?


Big thanks to @Osama for building theme settings and Javascript Bookmarklet to replace text with a link - Stack Overflow for guiding on the implementation.

What words do you auto-link?
Add <abbr> tags to words in posts
Special inline commands
How to add settings to your Discourse theme
How to automatically convert Keywords to Affiliate Links?
Javascript in theme component only runs once?
Add <abbr> tags to words in posts
Object Settings?
Any Autolinker solution for Discourse?
Add <abbr> tags to words in posts
Meta annotation sidepost for bots?
Abbreviations and acronyms plugin
URLs display only for registered

fantastic, system-wide feature… was thinking about this just the other day!

(Fellowship Forums) #5


First off, I’d just like to thank everyone for all the help provided to me over the past few weeks. I know I’ve been asking lots of questions - I am also a beginner to Discourse and coding in general, and the community here has been incredible.

I am wondering if it would be possible to add on a feature to this, which is very similar in nature. I think most of the functionality is built, my use case for this is slightly different however.

Would it be possible to have a box like this on a ‘Tags’ page, where the user can type in specific tag words manually, and it would create a customized url based on these words? For example, the image below would produce a url something like this: This would be a great feature for Tags Intersection, and would allow the user to specify the words in their intersection.




seems to be not showing when you add it to a theme:


tried adding to default… but doesn’t seem to be working as intended:

(Daniela) #7

It is not a problem related to this specific theme, see:

(Southpaw) #8

Sometimes one like is not enough. :heart: Office high-fives took place today as we thought through all the ways we could put this to use!

One question, though: Is the following a bug?

Most of my links are working, however urls that include appended parameters are failing.

For example, I want to use this link:

but when it is created from linkified words, clicking it results in:

The same link added to a post traditionally (pasted, or using the “link” icon from the toolbar) works.

(Sam Saffron) #10

Looks like @zogstrip fixed this FIX: don't track clicks · discourse/discourse-linkify-words@ef072b3 · GitHub … I just updated your component, can your refresh the problem page and try again?

Show an error page when click track fails
(Southpaw) #12

That appears to have fixed it! Thank you!!

(Sam Saffron) #13

Keep in mind, we are going to elevate this to a proper feature in Discourse in the “special actions on words” section, but it will take a bit.

I love that this is a component though cause we get to “test out components” in anger. @Osama / @joffreyjaffeux one huge omission we have here is that it is ultra mega super painful working with long lists in settings, try this out with 50 or so links to experience the pain. We need a different “list” control for managing long lists of things.

Add <abbr> tags to words in posts
(Joffrey Jaffeux) #14

do you have any idea in mind about this?

(Sam Saffron) #15

Honestly, I am not sure, but have a look at republic for an example of how painful this gets.

(Joffrey Jaffeux) #16

Agreed it’s a massive pain…

A first step would be to give it more width, but that wouldn’t make it perfect.

What do you think if I hide the part after the comma, and you can only see it when mouse overing ?

I think that would be good, you mostly care about the words you are linkifying when you look at the list.

(Sam Saffron) #17

I kind of think it needs another mode of item per row, that way at least you can tell what is going on in long lists

(Joffrey Jaffeux) #18

I see. Shouldn’t be hard to do, I already apply this kind of per multi-select modification for category colors, I have an idea, will work on it in the next days.

(Joffrey Jaffeux) #20

Here is my proposal:

A new site-setting type: dictionary.

  • one item per row
  • explicitly shows the key/value relation
  • ellipsis the end of the value so it’s always readable
  • will limit the height for the component so it becomes scrollable after something like 10 rows

If it works for you I will work on it beginning next week.

Better handling of site settings with large amount of content (big lists)
(Sam Saffron) #21

Do we have other site settings that need this?

(Joffrey Jaffeux) #22

not to my knowledge, but AFAIK it doesn’t have to be an explicit new type server side, it could only be a new type client site like (url-list, host-list…)

So in the end it would be very little code, it’s mostly a subclass of list-setting where I split the label and present it differently.

(Sam Saffron) #23

We should split this topic

I feel there are a few settings that list urls like allowed iframes and some others that can easily benefit from item-per-row, maybe even the user list in admin groups as well

I think we should start with a simple item per row mode prior to adding dictionary

(Joffrey Jaffeux) #25

After a discussion with sam:

  • rename our current “list” to “compact-list”, which will display as many items per row it can (list current behavior)
  • “list” will now only display one item per row
  • this shouldn’t touch server side client setting, default UI for list will be modified, and the new client side site setting “compact-list” will rely on “list”

Better handling of site settings with large amount of content (big lists)
(Ridha) #26

I think, there is a missing step in configuring Linkify component.

After this

Then, activate the linkify components in every theme.

I hope the last step should help others newbie like me.

I am certainly love this feature. :heart: