0

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

  • Could you be a little more specific about your question? Not understanding it doesn't tell us what part isn't making sense. Do you need help figuring out where this goes? Or are you concerned about what it does? – WebElaine Mar 3 at 14:01
  • What I mean is where do I place the link (I want to remove from all my posts) in that code. – Gideorlah Mar 5 at 9:07
0

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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