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 7562069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:19:19+00:00 2026-05-30T13:19:19+00:00

I created following shortcode function to call a menu on a specific location on

  • 0

I created following shortcode function to call a menu on a specific location on page

function servicesmenu() {
    return wp_nav_menu( array( 'theme_location' => 'services_nav', 'menu_id' => 'servicesmenu') );
}
add_shortcode('servicesMenu', 'servicesmenu');

Above code is working fine. But when i tried to wrap the shortcode in a DIV it’s not wrapping, the menu generated by shortcode is coming before div id=”services_rightarea”

<div id="services_rightarea">
    <!-- other content here -->
    [servicesMenu]
</div>

Any solution please

  • 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-05-30T13:19:21+00:00Added an answer on May 30, 2026 at 1:19 pm

    The problem is that the wp_nav_menu echos by default. You need to capture this echo in a variable and return it. This can be done with output buffering:

    function servicesmenu() {
    
        // Start output buffering
        ob_start(); 
    
        // The echo of this call is caught in the buffer
        wp_nav_menu( array('menu_id' => 'servicesmenu');
    
        // Capture contents of buffer in a variable
        $menu = ob_get_contents();
    
        // End buffering
        ob_end_clean();
    
        // Return your menu and bask in the warming glow of working code
        return $menu;
    }
    add_shortcode('servicesMenu', 'servicesmenu');
    

    Edit: I just noticed that you’re also using the theme_location property. This will try to insert the result of the wp_nav_menu call into servicesmenu menu, which was registered with register_nav_menu().

    Take the theme_location parameter out and the output buffering will work as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created the following interface: <?php interface Action { public function execute(\requests\Request $request, array
I have created following function to fill field of a form page, there is
I created the following function to simplify a piece of particularly complex code. CREATE
I created the following script to query a table and return the first 30
I created the following function with six args: nDone <- function(under,strike,ttoe,vol,rf,dy) { pnorm(((log(under/strike)+ (rf-dy+(vol^2)/2)*ttoe)/(vol*(ttoe^0.5))))
I created following an asp.net page with tiny editor. It is Ok, good work.
I have created following stored user defined it gets executed successfully. CREATE FUNCTION spherical_distance1(@a
I have created following rule in the .htaccess file located at the root of
I created the following code to calculate the duration between two timestamps which can
I created the following method for retrieving stored settings from the database: public String

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.