• Resolved Nick Satkovich

    (@nicksatkovich)


    I’m pulling H2 headers with get_the_content() for a section jumper (each H2 is a section) and the visibility settings aren’t being adhered to.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Nick Diego

    (@ndiego)

    Hi Nick,

    Would you be able to provide a code snippet of your implementation? This will allow me to do some testing and diagnose on my end.

    Block visibility is applied using the render_block filter based on block attributes. From my understanding, get_the_content() pulls the post content directly from the database but does not pass it through the the_content filter. More info here.

    I did a quick test using:

    
    1. echo get_the_content();
    2. echo apply_filters( 'the_content', get_the_content() );
    
    1. Using just get_the_content() did not trigger the visibility settings and also did not render a bunch of other blocks correctly in my testing. Looks like all the dynamic blocks were not rendered.
    2. However, passing get_the_content() through the the_content filter and everything worked as expected.

    I look forward to hearing from you.

    Best,
    Nick

    • This reply was modified 2 years, 5 months ago by Nick Diego.
    Thread Starter Nick Satkovich

    (@nicksatkovich)

    Hi Nick,

    Absolutely. Here’s what we’ve implemented: https://gist.github.com/nicksatkovich/e21a33340d9d7fbb88e8f12cd4492b3c

    Plugin Author Nick Diego

    (@ndiego)

    Perfect thanks. So if you update your $content variable to the following, you should be in good shape. I just tested, and everything is working as expected.

    $content = apply_filters( 'the_content', get_the_content() );

    Let me know if it works for you.

    Best,
    Nick

    Thread Starter Nick Satkovich

    (@nicksatkovich)

    Weird, if I var_dump $page_headings I’m getting int(0).

    Thread Starter Nick Satkovich

    (@nicksatkovich)

    Hi Nick,

    Just touching base to see if you saw my last response.

    Thanks!

    Plugin Author Nick Diego

    (@ndiego)

    Hi Nick,

    You will need to use apply_filters( 'the_content', get_the_content() ) to get the content with the visibility attributes applied. I have tested this and it works as expected.

    My guess is that there might be an issue with the regular expression in preg_match_all(). It was working in my test, but I just had a very simple setup with just a few Heading blocks on the page.

    If you can provide an example of the block markup that you are working with, I may be able to assist.

    Best,
    Nick

    Plugin Author Nick Diego

    (@ndiego)

    Closing this out since the previous comment provides a solution. But, if there is any additional feedback, or if I can be of further assistance, just let me know.

    Best,
    Nick

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Visibility not blocked with get_the_content()?’ is closed to new replies.