WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields: Widget Area Field
Needs Output Buffering (1 post)

  1. JoshRowland
    Member
    Posted 3 weeks 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 />

    https://wordpress.org/plugins/advanced-custom-fields-widget-area-field/

Reply

You must log in to post.

About this Plugin

About this Topic