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 have a WP website, and a related shop that's on a different domain / site. I want to have one navbar that I can update in wordpress that will also update the shop without me having to do it twice.

Aiming to do this using some JS like this:

$.getJSON("http://some-wordpress-site/menu-only/?jsonCallback=?", function(json) {
            $('#navWrapper').append(); 
});

In the menu-only template, I'm trying to create application/json feed for the shop to read and spit out the menu. I.e.:

<?php
/*
  Template Name: Menu Only
 */
header('Content-type: application/json');
?>
<?php echo htmlentities($_GET['jsonCallback']) ?>
(
<?php
echo json_encode(array(
    'content' => wp_nav_menu(array('echo' => false, 'menu' => 'Navigation', 'container_class' => 'menu-header', 'walker' => new mainnav_menu_walker())))
)
?>
);

What ends up happening when I visit my JSON menu link on the WP site is the wp_nav_menu has spat itself out in the wrong location. The result (without copy/pasting a huge chunk of code in here) looks a bit like this:

(
... massive menu html code block ...
{"content":false});
);

Whereas the menu should be echoing where false is. Has anyone had experience with wp_nav_menu acting oddly like this? I have a fairly complicated walker operating behind it, which works fine on the wordpress site.

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.