0

I used the 'the_content' filter to check if the content of an page is empty and to set an alternative content:

add_filter( 'the_content', 'my_content' );     
function my_content( $content ) {
    // check if we the posttype is correct   -------------------------------
    ...
    if (strlen($content) == 0) {
      return 'new content';
    }
    return $content;
}

When I open an empty post with the correct posttype I will get an empty $content with string length (608). In this case will show and emtpy page and not the "new content" :(

I included the following debug information:

    $temp = trim($content);
    var_dump($temp);

    if (strlen($content) == 0) {
      return 'new content';
    }

and get as an result: string(608) " "

Any Idea what is going on and how to fix it?

  • Why don't you try if(empty($content)) condition? – Faisal Alvi Mar 6 '17 at 13:09
  • Please share full code because I have tried to figure it out but I am getting correct results. – Faisal Alvi Mar 6 '17 at 13:14
  • thx for pushing me :) the riddle is solved: one plugin "addthis.com" injected some content before my filter but :) addthis just added an html comment <!-- some text --> and this text will not be shown in the browser even if I echo or var_dump it :) so sorry!!! I was only able to see it by iterating over the string... – user3361559 Mar 6 '17 at 14:23
  • If the riddle is solved then answer yourself below and accept it or close this question. thanks – Faisal Alvi Mar 7 '17 at 5:22
0

It was an presentation issue as the content was injected by another plugin and it was an HTML comment "" and this Text will not be shown by an echo or even an print_r() or var_dump()

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.