0

I have a wordpress site with lots of links in it. Every link has the extension ".html" (like <a href="https://example.com/about.html>).

I like to add a filter which searches for the ".html" and replaces it with "" (<a href="https://example.com/about>) on all pages.

I have tried to get this done with str_ireplace and the gettext filter.

function kb_rename_links( $kb_rename_item ) 
{  
$kb_rename_item = str_ireplace( '.html', '', $kb_rename_item );

return $kb_rename_item;
}

add_filter( 'gettext', 'kb_rename_links' );

This snipped doesn't do the job (it works for plain text). I think the gettext filter isn't the right one for this job or even i need a action here. But i am to noobish to find the right one.

Thanks for your help

2 Answers2

0

I think a better solution would be to modify the .htaccess file to remove the .html extensions. This way you don't have to touch the code at all.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

source

Edit: Here is a similar stackoverflow post to my solution.

Ian
  • 98
  • 6
  • yes, i use this workaround now but i don't like this solution cause i also like to change an string inside an .img tag as soon as i find a solution. T – Christoph Schober May 06 '18 at 19:21
0

Try 'the_content' filter instead ot gettext

Alexey
  • 520
  • 3
  • 9