I found this code but I don't understand it.
add_filter( 'the_content', 'misha_remove_all_a' );
function misha_remove_all_a( $content ){
return preg_replace('#<a.*?>(.*?)</a>#is', '\1', $content);
}
This is the link
My website address is this
I found this code but I don't understand it.
add_filter( 'the_content', 'misha_remove_all_a' );
function misha_remove_all_a( $content ){
return preg_replace('#<a.*?>(.*?)</a>#is', '\1', $content);
}
This is the link
My website address is this
This code is a filter, as shown by the initial add_filter
call. This type of code can either be placed in a custom plugin, or a child theme or custom theme's functions.php
file. (You don't want to place it in an existing functions.php
file because whenever you update the theme, it will get lost.)
It will automatically run on the front-end (public) view of every post, page, and custom post type. That's because the filter is added to the_content
, which takes the content from the database and renders it out as HTML on the front end.
If you'd like to make this a plugin, you just need an opening PHP tag and a comment to let WordPress recognize it as a plugin:
<?php
/* Plugin Name: Strip Links from Content */
add_filter( 'the_content', 'misha_remove_all_a' );
function misha_remove_all_a( $content ){
return preg_replace('#<a.*?>(.*?)</a>#is', '\1', $content);
}
?>
Save it as strip-links.php
, upload it to /wp-content/plugins/strip-links/
, and you can then activate the plugin from wp-admin.