0

I was trying to dynamically create markup on my page and run inside that markup a custom hook like this:

add_action( 'genesis_after', 'mw_add_offcanvas' );
function mw_add_offcanvas()
{
    $out = '<div class="shifter-navigation">';
    /**
     * Using this hook:
     * mw_add_offcanvas_sidebar
     * mw_offcanvas_menu
     */
    $out .= do_action( 'mw_inside_offcanvas' );;
    $out .= '</div>';
    echo $out;
}

The goal was to then be able to assign widget areas or menus to that hook:

function mw_add_offcanvas_sidebar() {
    genesis_widget_area( 'sidebar-navigation', array(
      'before' => '<div class="widget-area">',
      'after' => '</div>',
    ) );
}

add_action( 'mw_inside_offcanvas', 'mw_add_offcanvas_sidebar' );

This actually works although the elements are outputted outside the markup dinamically generated with the mw_add_offcanvas() function.

How can I achieve this?

Luis Martins
  • 1,421
  • 2
  • 18
  • 32

1 Answers1

0

Found a solution in StudioPress forums, posting here for reference:

function mw_add_offcanvas()
{
    $out = '<div class="shifter-navigation">';
    /**
     * Using this hook:
     * mw_add_offcanvas_sidebar
     * mw_offcanvas_menu
     */
    ob_start();
    do_action( 'mw_inside_offcanvas' );
    $out .= ob_get_contents();
    ob_get_clean();
    $out .= '</div>';
    echo $out;
}
Luis Martins
  • 1,421
  • 2
  • 18
  • 32