0

I was asked by a customer about the possibility to put a menu from a WP installation into another WP, whereas are independent installations, each one for its domain. The point is: I developed a website in WP (using Woocommerce) and months after we developed a blog, with another layout structure but keeping the visual ID for the brand. Now, she wants to put the main menu from her main website into the blog, and all the options on that menu needs to be dynamic, so, if she decides to add another category to that menu, it should be shown on the blog too, automatically.

Is it possible to do something like that, such as integrate a WP installation with another? Basically I need to put a menu from a WP installation into another, each one on a separated domain. Can someone help me with this big problem??

Thanks at all !

0

This is actually quite possible, however, there are some specific things that you need to do to get it to work.

First, create a file on your wordpress installation that currently has that menu, for the demonstration, we're calling it myoutsidermenu.php, in a theme called theme_name. Once you are done that, edit the php code so that it echoes your menu item into that file using the wordpress engine. I suppose you could include the CSS styling for the menu itself, but that isn't entirely necessary. Remember, this file should only contain the menu, and no other wordpress elements, or they'll be included on the receiving end which might cause you problems.

Once you are done that, on the receiving end, where you want your menu to show up, put the following code:

<?php 
$doc = new DOMDocument();
$doc->loadHTMLFile('http://example.com/wp-content/themes/theme_name/myoutsidermenu.php');
echo $doc->saveHTML();
?>

Where the URL corresponds to the URL of the file that echoes the menu item. Now, remember to make sure to include CSS styling somewhere on your receiving end to make it display how you want it to display.

I'm not sure about any best-practices here, but it should get the job done.

7
  • And where would these menu items point? To the old domain.
    – vancoder
    Jun 27 '14 at 17:43
  • 1
    Sounds great, I will test it. Just a question: is the DOMDocument()" function native from PHP? Jun 27 '14 at 17:44
  • Jao, I believe it comes standard with php 5 and up. @vancoder Isn't that the point? They want their customers to easily get to their webstore, not to re-create the webstore on their new domain.
    – Adam
    Jun 27 '14 at 17:47
  • "jao" is horrible in Brazil, it's "joao"! Jun 27 '14 at 19:52
  • @joaosvu my bad, typo... did not realise - sorry! No wonder your name didn't pop up to tag you, haha
    – Adam
    Jun 27 '14 at 21:28
0
<?php 
  error_reporting(0);
  $doc = new DOMDocument();
   $doc->loadHTMLFile('http://example.com/wp-content/themes/theme_name/myoutsidermenu.php');
  echo $doc->saveHTML();
 ?>

note, I added the removal of error reporting as this above method output warnings when pulling data across domains.

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.