WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wanted to use WordPress menu management then show it on outside wordpress installion php file with html but I got this error

PHP Fatal error:  Call to a member function get_queried_object() on a non-object in .../blog/wp-includes/nav-menu-template.php on line 395

Here how I do it in on php file with test.php

$documentroot = $_SERVER['DOCUMENT_ROOT'];
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<div id="header">
 <div id="main-nav">
<?php if ( has_nav_menu( 'landingpage-menu' ) ) { /* if menu location 'secondary-menu' exists then use custom menu */ ?>
<?php wp_nav_menu( array( 'theme_location' => 'landingpage-menu', 'container' => '', 'depth' => 1 ) ); ?>
<?php } ?>

is there wrong on how I implement it? or I'm missing something?

share|improve this question

That should work fine. Likely problems are either the incorrect path[1] at the top or no menu named landingpage-menu[2].

[1] For the pathing, try this at the top of your file and see if it's doing what you expect.

    $documentroot = $_SERVER['DOCUMENT_ROOT'];
    echo "documentroot is: " . $documentroot . "<br><br>";

    $filecontents = file_get_contents($documentroot.'/blog/wp-load.php');
    echo $filecontents;

[2] For the menus, try this:

<h2>Menu Locations</h2>
    <?php print_r($menuLocations); ?>

    <?php print_r($menus); ?>

It should list out all menus and menu locations.

share|improve this answer

You can use this code and it will really help you a lot

require( '../wp-load.php' );

echo 'new content outside WordPress';

share|improve this answer
Can you explain a little bit as how it helps in addition to the code provided. – bravokeyl Jul 15 at 6:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.