Dynamic_sidebar load in string makeup

You could use output buffering to catch the display of the sidebar. This does make it a bit more difficult to debug should you need to but it will get you what you need: ob_start(); dynamic_sidebar( ‘header-widget’ ); $sidebar = ob_get_clean(); $menu_markup = ‘<header class=”%s header”>’ . $sidebar . ‘</div>’;

loading a php file to a specific page id

Use the template hierarchy, you can name files in your theme so that they load in specific circumstances. E.g. the template category-unicorns.php will be used instead when on the category with the slug unicorns