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
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]
Edit: Here is a similar stackoverflow post to my solution.
尝试使用“ the_content”过滤器,而不是ot gettext
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.