Hi,
I need to parse the_content and find elements that I have set a custom class to with Beaver builder.
When I output the result from get_the_content() I can’t se the custom classes I’ve added with Beaver Builder? How can I come around this?
Hey Daniel. Let me make sure I am understanding you correctly. After building a page with Beaver Builder, you’re calling get_the_content and then parsing the code? Are you setting a custom class from within the page builder?
If you don’t mind me asking, can you elaborate a bit more on why you’re doing this? I just want to better understand the problem you’re trying to solve.
Off the top of my head, I am not sure. I will have to experiment a bit with this and see what I can find out. Any additional info would be great! Thanks much!
Hi Robby,
Sure, I will make a try to explain.
It’s correct, I’m setting custom classes from within the page builder.
I’m try to create a shortcode that will generate a menu with anchors from the content.
So that why I’m trying to parse the content with get_the_content, and with PHP DOM object I will parse it and find all classes with a prefix (<h1 class=“link-section1”>Headline</h1>).
And then I will genereate the menu from this.
My problem is that when I’m calling get_the_content I only get <h1>-tags with no classes. And I don’t get the other Beaver builder formatting either?
Thanks for clarifying! Justin (he’s the developer/master mind behind BB) is out of town this week. Although, he posted this in our Slack chat this morning:
Frankly, I am not 100% sure how to help/answer, but I thought I would relay the message in case that’s helpful.
Sorry to send you on a wild goose chase here. When he is back to the office, we can figure out a better answer for you. This is one of those questions where I’d need to spend an hour digging through the code whereas he can likely answer it in a few minutes. We’ll follow up in more detail ASAP. Thanks for your patience
The function get_the_content will return the content from the post editor. In order to get the builder’s content, you’ll need to use the function the_content as the builder takes over that using add_filter(‘the_content’, ‘FLBuilder::render_content’); to render its markup.
If you’re querying posts from the database outside of the loop, you could do something like this to access content from that function in php…
/* Do your post querying and setup first here. */
ob_start();
the_content();
$content = ob_get_clean();
Hi Justin,
Thanks for you answer. I have tried this now, I get the content into a php variable but my problem still exists… I have set a CSS class in BB advanced tab in the content, but I can’t get the_content rendered with BB. I still only see a <h1> without my class??
Custom classes are applied to the module div wrapper, not the elements within it like the H1 tag. Can you check to see if it’s there? If not, can you paste an example of the code you are using?