I’ve encountered a strange problem with menus after moving WordPress from local environment to a live server.
On my local server, the menus are displayed correctly, while on the live server, there is only a piece of the menu code shown instead of the actual menu. (Basically, it cuts off the code after the =>
in the first argument of the array and outputs the rest of the code instead of showing the menu.)
local server version
live server version
Everything else is working â the backend is fine, all the links work correctly too, which makes me think that the migration went okay, and the problem is in the PHP itself.
The whole code for the menu in header.php
looks like this (there are two menus next to each other):
<div class="collapse navbar-collapse" id="main-navigation-collapse">
<? wp_nav_menu (array(
'sort_column' => 'menu_order',
'menu_class' => 'nav navbar-nav list-inline',
'theme_location' => 'primary'
)); ?>
<? wp_nav_menu (array(
'sort_column' => 'menu_order',
'menu_class' => 'nav navbar-nav navbar-right list-inline',
'theme_location' => 'top-menu'
)); ?>
</div>
The menus are registered in functions.php
like this:
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'be-emobil' ),
'top-menu' => __('Top Menu', 'be-emobil'),
'footer-menu' => __('Footer Menu', 'be-emobil'),
'footer-menu-2' => __('Footer Menu 2', 'be-emobil')
) );
Some info that might be useful:
- I’m using the _s (Underscores) theme as my base.
- Local PHP version is 5.6.7
- Live PHP version is 5.6.8-pl0-gentoo
Any idea why this might be happening or how I could find out what is wrong?
Your live server doesn’t have Short Tags enabled.
You can do the following:
Depending on you access to php.ini, .htaccess etc. on the live server, you’ll want to choose your solution accordingly
Try enabling short tags?
Add
To your php.ini and restart php-fpm and you web server.
Replace your Shorttags
<?
with<?php
they do not work on every environment.Or try to turn them on in the php.ini if you have access to it.