Ready to get started?Download WordPress


Advanced Custom Fields: Widget Area Field
[resolved] Needs Output Buffering (2 posts)

  1. JoshRowland
    Posted 8 months ago #

    This plugin is great and is really close to what I needed. I did have to modify it a little bit to make it work. The current plugin uses dynamic_sidebar() function which is outputting content outside of your $value variable and isn't returned with the function.

    By adding ob_start() and ob_get_contents you can save this output and return it properly within your div. (If you look now, the <div id="secondary"> gets displayed after the sidebar)

    Here is the final code change to make this work so that ACF functions get_field (returns the html) and the_field (displays the html) work properly.

    <br />
    function format_value_for_api($value, $post_id, $field)<br />
    {<br />
    	$value = '';<br />
    	if ( is_active_sidebar( $field['value'] ) ) :<br />
    		$value .= '<div id="secondary" class="widget-area" role="complementary">';<br />
    			ob_start();<br />
    			dynamic_sidebar( $field['value'] );<br />
    			$value .= ob_get_contents();<br />
    			ob_end_clean();<br />
    		$value .= '</div><!-- #secondary -->';<br />
    	endif;<br />
    	return $value;<br />
    }<br />


  2. Dustin Filippini
    Plugin Author

    Posted 4 months ago #

    As of v1.0, I have fixed this issue. Thanks.


You must log in to post.

About this Plugin

About this Topic