Trying to use ChristoKiwi's https://stackoverflow.com/questions/19356897/removing-links-from-posts-in-wordpress-using-query/61652078#61652078 approach for deleting links in Joomla articles, but having issues with this example:

      class="responsive caption"
      style="margin-right: 10px; float: left;"
      >Rohm </a
   >kündigt mit dem BM14270MUV-LB einen der kleinsten berührungslosen
   Stromsensoren der Industrie an. Der neue Baustein verbraucht nur minimal
   Strom und ist mit 3,5 x 3,5 x 1,0 mm sehr kompakt.&nbsp;Damit eignet er sich
   für Industrieanlagen und Verbrauchergeräte, die Betriebsbedingungen über den
   Stromfluss erfassen wie batteriebetriebene Drohnen, Solaranlagen und Server
   in Rechenzentren.

The query

UPDATE jos_content SET jos_content.introtext = REPLACE(jos_content.introtext, substring_index( substring_index(jos_content.introtext, 'title="', -1), '"', 1),'')

deletes not only the text within the "title" but also the word "Rohm" after the link.

How to delete the entire link with all the attributes completely?

  • Welcome to JSE, Jens, please take our tour. I see that when you registered here, that you did not associate your registration with your pre-existing Stack Exchange account (your Stack Overflow acct); please read about merging your accts. Please add a link to your question that references where "ChristoKiwi's approach" is on the web. I feel like hacking at introtext data via SUBSTRING_INDEX() surgery is a suboptimal approach. What does your template look like? Commented May 7, 2020 at 22:16
  • @mickmackusa Have added the link to ChristoKiwi. With this website we're using "Notio" a Rockettheme template and the JCE editor. Have a look here: developmentscout.com Commented May 7, 2020 at 23:22

2 Answers 2


It appears on review of Christo Kiwi's solution that it only works with a link which has an identical part of which you wish to remove.

Based on your example, I suspect that your link is a variable and so you may need to take a slightly different approach.

  1. You first need to identify the start position and end position of the string component in the intro text that you wish to remove.
  2. Once you have found the start and end positions (which you can check using a select statement) then you can build your update/replace based on that. For example, you may need to find the position of <a dir and then the position of the next > after that and use that in your replace string.

I would definitely start by creating a SELECT query to make sure that you are correctly getting the article ID and the string part that you wish to replace and then build that into your update query.

In my particular case, I was looking for multiple links of the same type in intro text so I had to work out the position of the first start and end, then the second start and end, then the third start and end and replace all three.

Here is a snippet of code which may help you - I've used LOCATE() and SUBSTRING() to first check that the data I was going to replace was what I was expecting, then I built that into my replace function.

    SUBSTRING(introtext, LOCATE('<li><a href="index.php?option=com_docman', introtext), 4 + LOCATE('/li>', introtext, LOCATE('<li><a href="index.php?option=com_docman', introtext)) - LOCATE('<li><a href="index.php?option=com_docman', introtext)) AS pos1text
FROM `d8bk2_content` 
WHERE id >395
  AND introtext LIKE '%<li><a href="index.php?option=com_docman%'

In your case, you would LOCATE('<a dir') and then the next closing tag etc.

  • Thank you very much @sirobertson for your detailed answer. In the meantime I tried to learn and modify your snippet for my cases which worked, but noticed also that there are so much possibilities to "create" an external link. Therefore I decided to deleted them "manually" via the JCE editor and eliminate simultaneously some unnecessary content as well. Commented May 10, 2020 at 16:35
  • @user13488789 if you decided not to use any of the answers provided, please post why and how you resolved your issue as a new answer on this page. Then you may accept your own answer. When answering (any question), please be generous with your explanation so that future researchers can learn from your insights. Commented May 16, 2020 at 4:47

As an alternative, you could have opened up your template and used php's native strip_tags function which allows a list of exceptions, so...

echo strip_tags($this->item->introtext, '<img><p><listofallowedelements>');
  • Thank you so much guys for all your answers. I really appreciate it!. After spending hours on figuring out how to create a query to eliminate the different links, which changes a lot within 10 years of Joomla, the result was that there are so much possibilities. This ended up that the content table was altered so that the text result at the frontend shows some highlighted text without a link, but with a different color. Commented May 18, 2020 at 13:05
  • May be due to the combination of the JCE editor. I don't know. Additional I had to delete some other text so that I decided to make all these changes manually. Yes, I gave up. That's not really funny because of approx. 10.000 articles but less time towards to try to deal with all the "destroyed" content tables ;-) Commented May 18, 2020 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.