0

I was trying to remove a div having some ID from the_content WordPress. I am trying to achieve something like this

jQuery( "#some_id" ).remove();

but on server side,

I don't have a clue how I can do this on server side within the_content filter hook.

add_filter( 'the_content', 'my_the_content_filter', 20 );
function my_the_content_filter( $content ) {


    $content.find('#some_id').remove();


    return $content;
}
0

with the_content filter hook you can modify the content using PHP preg_replace search and replace

function remove_specific_wrapper($content) {
    $content = preg_replace('#<div[^>]*id="some_id"[^>]*>.*?</div>#is', '', $content);
    return $content;
}
add_filter('the_content', 'remove_specific_wrapper');
0

I had posted same question on Stackoverflow as well, and below answer worked for me. Maybe someone else need this too. https://stackoverflow.com/a/43743269/2829625

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.