How can I hyperlink a specific word in multiple pages of single website at once.
Detail
For example I have a website named word.com and there are 100 pages on this website. Now I have the word Dog 100 times on these 100 pages. And I want to hyperlink the word Dog with a detailed Wikipedia page.
How can I do it in HTML and CSS?
I don’t know much about coding.
2
Answers
To add a hyperlink specific word "DOG" you will need to have 100 different files if you have 100 pages of your website as it is not possible to do it in a single file.
HTML
CSS
You will need to repeat this for all pages.
You can’t do it with only HTML and CSS. You need to write a script which reads the text containing the word "dog" and then puts an anchor
<a>
tag around it with the correcthref
. I recommend using JavaScript for this, since it is relatively easy to read from HTML elements with JavaScript.The following code turns every occurence of dog into a link, even if its in another word.
The regex
/Dog/gi
matches every occurence of "dog", case-insensitively.The
$&
inside the replacement string is the matched text. I use this to preserve the casing.