Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:29:43+00:00 2026-06-17T20:29:43+00:00

I am new to wordpress themes and PHP. (I don’t believe this is specific

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:29:44+00:00Added an answer on June 17, 2026 at 8:29 pm

    I think I know what you are trying to do here. Give this a shot.

    <?php
    function rfttc_insert_nav_menu ($position){
       $poswanted = 'above';
       $nav_code = 
      '<nav id="site-navigation" class="main-navigation" role="navigation">
       <h3 class="menu-toggle">'. _e( 'Menu', 'twentytwelve' ) . '</h3>
       <a class="assistive-text" href="#content" title="' . esc_attr_e( 'Skip to content', 'twentytwelve' ) . '">' . _e( 'Skip to content', 'twentytwelve' ) . '</a>' . wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ) . '</nav><!-- #site-navigation -->';
    
      if($position == $poswanted) return $nav_code;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error : Parse error: syntax error, unexpected T_OBJECT_OPERATOR in wp-content/themes/phil/page.php
Before everything happened, I was running this wordpress install for developing themes using xampp.
I'm testing a new template for a wordpress based site, and I'd like to
I am new to making WordPress themes but I have managed to include the
This must be an easy question for those who are not new to Wordpress
I'm setting an instance of an object in functions.php , like this: $foo =
Recently installed new wordpress theme. The problem is, there are only following font options
I installed new wordpress . and made some changes in twentyten theme.. only color
I'm working on a new design for my current Wordpress theme. On the old
I have installed a complete blank theme with no CSS in my new wordpress

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.