• Hi!
    I have used this expression in the divi content visibility field to hide a header:

    get_the_content() !==”

    That worked well but I found that if there’s a newline/tab/whitespace in the description and nothing else then “get_the_content” returns true.

    So I tried with this expression:

    preg_match(‘/^(?![\s\S])|(\s*[\s])$/g’, get_the_content()) == 0

    But that doesn’t work. The header is displayed no matter whether there’s content or not.

Viewing 1 replies (of 1 total)
  • Thread Starter norrlandsit

    (@norrlandsit)

    Regex token /g is not allowed in preg_match, so I started to use preg_match_all

    I found that if I simplified the expression to:

    preg_match_all('/^\s*$/', '') == 0
    Then it works and the boolean value is negated if the string contains visible letters as:
    preg_match_all('/^\s*$/', 'hello how are you') == 0

    But if I change the string to a escape sequence (“\t\n”) or a space (” “) then it doesn’t work as expected which might explain why
    preg_match_all('/^\s*$/', get_the_content()) == 0
    works as expected only if there is visible content or nothing at all.

Viewing 1 replies (of 1 total)
  • The topic ‘Hide when content description is truly empty’ is closed to new replies.