How to get sidebar’s content inside admin-ajax?

I’m using a modal to display some content via an admin-ajax request.

Now I have problem outputting the content of a sidebar (text widgets, used for adding advertisement scripts). When I directly use dynamic_sidebar('ads'), it outputs the content randomly all over the modal.

What I was able to do was to use output buffering.

ob_start();
    dynamic_sidebar('ads');
    $ads = ob_get_contents();
ob_end_clean();

And then use $ads later.

Isn’t there a better way to do this?

PS : The modal script does not support the REST-API.

0

Leave a Comment