0

I am getting this error which

Fatal error: Uncaught Error: Call to undefined function wp_nav_menu() in /home/stageidg/public_html/idg/wp-content/themes/idg-child/secondmenu.php:2 Stack trace: #0 {main} thrown in /home/stageidg/public_html/idg/wp-content/themes/idg-child/secondmenu.php on line 2

line 2 in the php file is this:

wp_nav_menu( array('menu' => 'Services', 'theme_location'=>'services' ) );

and its being called by this jquery code:

$.ajax(
{
url: "http://example.com/idg/wp-content/themes/idg-child/secondmenu.php", // path to your PHP file
dataType:"html",
success: function(data)
{

   $(data).appendTo(inner_overlay); // load-into-div is the ID of the DIV where you load the <select>

} // success
}); // ajax

any idea? what am i doing wrong?

New contributor
jgax87 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 2
    secondmenu.php is called separately, not in a WordPress context, so it doesn't know anything about the WordPress functions. – fuxia Jun 11 at 20:11
-1

Yes, like @fuxia says, include wp-load.php to get the WordPress API (wp_nav_menu included) to use. In your case:

<?php

include '../../../../wp-load.php';

This way you did is not wrong but there are better ways to use AJAX in WordPress:

https://codex.wordpress.org/AJAX_in_Plugins

Be happy, my friend!

  • this worked! well i had to do another way but it did lead me to the answer which was... define( 'WP_USE_THEMES', false ); // Don't load theme support functionality require( '../../../wp-load.php' ); thank you for the prompt response! – jgax87 Jun 11 at 21:47

Your Answer

jgax87 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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