Output menu navigation in php file

I have a WordPress site which generates a menu at the top of the page with this:

<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>

This line is located somewhere in a file called header.php.

(Location in wp-admin is: Appearance -> Editor -> Templates -> Header (header.php)

What i need to do is use the line i gave earlier:

<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>

In a separate php file. So that when i navigate to: `http://mijnwpsite.com/justthemenu.php

That it only outputs the menu. No doctype or anything.

What steps do i have to take for this?

Thanks in advance.

1 Answer
1

You would require the path to wp-blog-header.php to access WordPress functionality in a
standalone PHP file. So your justthemenu.php file should contain the following code.

<?php
    require('/wp-blog-header.php');
    wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) );
?>

Leave a Comment