I am new to wordpress themes and PHP. (I don't believe this is specific to WP) I would like to know the best way to store a block of HTML (with embeded PHP code) in a PHP variable.
<?php
function rfttc_insert_nav_menu ($position){
$poswanted = 'above';
$nav_code =
'<nav id="site-navigation" class="main-navigation" role="navigation">
<h3 class="menu-toggle"><?php _e( \'Menu\', \'twentytwelve\' ); ?></h3>
<a class="assistive-text" href="#content" title="<?php esc_attr_e( \'Skip to content\', \'twentytwelve\' ); ?>"><?php _e( \'Skip to content\', \'twentytwelve\' ); ?></a>
<?php wp_nav_menu( array( \'theme_location\' => \'primary\', \'menu_class\' => \'nav-menu\' ) ); ?>
</nav><!-- #site-navigation -->'
if($position == $poswanted)
return $nav_code;
}
?>
Reading through many questions here leads me to believe that nowdoc and heredoc are not good choices. I have tried single quotes and escaping the single quotes inside. Same with double quotes. Both attempts resulted in error messages.
Any help here would be appreciated.
EDIT* The following code is what finally worked.
<?php
function rfttc_insert_nav_menu ($position){
$poswanted = 'below';
if($position == $poswanted){?>
<nav id="site-navigation" class="main-navigation" role="navigation">
<h3 class="menu-toggle"><?php __( 'Menu', 'twentytwelve' )?> </h3>
<a class="assistive-text" href="#content" title="<?php
esc_attr_e( 'Skip to content', 'twentytwelve' );
?>"><?php _e( 'Skip to content', 'twentytwelve' );?>"</a>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) );?>
</nav><!-- #site-navigation -->
<?php
}
}
?>
Thanks to TJohnW for pointing me in the right direction: processing the inline PHP instead of trying to insert it.