Let's say I have these texts in my Wordpress title, post content and comments:
#TSLA
$TSLA
What I want to do is for Wordpress to identify the text #TSLA and $TSLA and automatically replace with a hyperlink, like this:
<a href="https://www.mywebsite.com/?s=TSLA">#TSLA</a>
<a href="https://www.mywebsite.com/?s=TSLA">$TSLA</a>
As for $, I just want to add a hyperlink for alphabet (A to Z), not with numbers.
Basically, very similar to what Twitter does.
Is there any function.php code to do that?
Thank you.
EDIT: Ok so, I think I'm getting somewhere thanks to Markus Zeller.
Basically here's what I have got so far:
<?php
$x = "#TSLA";
$z = preg_replace("/^#*/", "", $x);
echo "<a href='?s=$z'>#$z</a>";
?>
which is echoing exactly what I need.
Finding the line that begins with # and replaces with a hyperlink.
I still have two things to figured out:
- How to do the same with $ instead of #.
- It's now echoeing, I need it to be globally replaced on wordpress by putting a line in functions.php
Any further help would be appreciated.