WordPress shows PHP code instead of menu content

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.)

Read More

local server version
local server version


live 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?

Related posts

Leave a Reply

3 comments

  1. Your live server doesn’t have Short Tags enabled.

    You can do the following:

    • Change the <? to <?php
    • Enable short tags in php.ini
    • Enable short tags in your .htaccess file
    • Use php ini_set to enable short tags in the file

    Depending on you access to php.ini, .htaccess etc. on the live server, you’ll want to choose your solution accordingly