(As a preface, I know this is going to sound absurd, but please bear with me. I'm aware this is unideal and atypical.)

What I need to do is put wp_nav_menu inside an iFrame so I can view it on a non-WordPress-powered site. (Essentially, I have a WP-powered site where the user will have to leave the site to make a purchase. However, on that site, I'd like the page to look, feel and function -- primarily from the backend -- in the same way the rest of the WP-powered site would.)

I would create a separate nav.php and try to embed that in an iFrame, but WP blocks direct access to a file in the theme folder. Is there somewhere else I could put it? Or is there some other way I can unblock access to this file? (Not the route I'd prefer to go, but if it works, I'll take it)

My only other option is using something like a nav.html page, but I have no idea how I can run the usual WP PHP functions within this .html page.


create a .php file within the root WP folder:

  define('WP_USE_THEMES', false);
  wp_nav_menu(array('theme_location' => 'my_menu')); // change it with your menu location

and call it in your .html page (as a iframe). These only gets you the menu HTML, so you'll also need to import the theme CSS styles. Not sure how iframe content is styled, you might need to add them inside the .php file too...

There are other solutions, like using javascript to request your homepage HTML, then get the menu element from the results and append it into your html-powered website

Your Answer

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.