Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

<?php 
$documentroot = $_SERVER['DOCUMENT_ROOT'];
include_once($documentroot.'/blog/wp-load.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>

</head>

<body>
<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 } ?>
 </div>
</div>
</body>
</html>

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

share|improve this question

1 Answer 1

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.

<?php 
    $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>
<pre>
    <?php print_r($menuLocations); ?>
</pre>

<h2>Menus</h2>
<pre>
    <?php print_r($menus); ?>
</pre>

It should list out all menus and menu locations.

share|improve this answer

Your Answer

 
discard

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.