0

Im trying to add filter but only when the_content is not empty. So I was trying do something like that:

<?php
   $thecontent = get_the_content();
   if(!empty($thecontent)) {

   add_filter('the_content', 'gs_add_img_lazy_markup', 15);

} ?>

but without results. How should I do it propertly?

edit

What I want to do is create one function with two filters, but one this function should be done only when the_content is not empty. Right now I did this:

add_filter('the_content', 'content_image_markup', 15);
function content_image_markup($the_content) { 
$thecontent = get_the_content();
   if(!empty($thecontent)) {
        // function content
    }
}

add_filter('acf_the_content', 'acf_content_image_markup', 15); 
function acf_content_image_markup($the_content) {
        // the same function content what above         
}

how to makes this easer?

  • 3
    You need to do your check if the content is empty inside the gs_add_img_lazy_markup function. – mrben522 Apr 18 at 17:57
0

Based on your edits, you want one function to apply to two different filters. All you need to do is use the same function on both filters. I haven't tested this, but it should work:

function content_image_markup($content) {
    if( !empty($content) ) {
        // example of changing the content
        $content=$content . ' append this to content';
    }
    return $content
}

add_filter('the_content', 'content_image_markup', 15);
add_filter('acf_the_content', 'content_image_markup', 15);
  • I did like you said and it works. But look at my question, there is what exacly I want to do. – Piotr Milecki Apr 18 at 19:22

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.