0

I've got an odd problem creating a wordpress custom theme. For some reason

hello <?php echo 'world'; ?>

is being displayed as html

hello <?php echo 'world'; ?>

instead of

hello world

I've produced lots of wordpress sites before, but this is the first on an amazon server Any help would be much appreciated. Mark

Website is lmof.uk/demo

header.php (As much as stackoverflow will let me post)

<html xmlns="http://www.w3.org/1999/xhtml">

<? global $woocommerce; ?>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" / >

<title><?php wp_title(''); ?></title>

<link rel="shortcut icon" href="<?=get_template_directory_uri()?>/images/favicon.png" />

<link href='http://fonts.googleapis.com/css?family=Droid+Serif' rel='stylesheet' type='text/css'>

<!--[if IE 7]><link rel="stylesheet" href="ie7.css" type="text/css" media="screen"> <![endif]-->

<? wp_enqueue_script('jquery'); ?>

<? wp_enqueue_script('bootstrapcss'); ?>

<? wp_head(); ?>

<link href="<? bloginfo('stylesheet_url')?>" media="screen" rel="stylesheet" type="text/css" />

<script type="text/javascript">

  $(document).ready(function(){

    var page = $("body").attr("id");

    $(".page-"+page).addClass("active");

  });

</script>

<script>

  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)

  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');



  ga('create', 'UA-51095016-1', 'sample4u.co.uk');

  ga('send', 'pageview');



</script>

</head>

<?php if(is_page()) { $page_slug = 'page-'.$post->post_name; } ?>



<body id="<?

  $exp = explode("?",$_SERVER['REQUEST_URI']);

  echo end(array_filter(explode("/",$exp[0]))) ?>" <?php body_class($page_slug); ?>

  data-spy="scroll" data-target="#navbar-category" data-offset="60"> 
Mark
  • 70
  • 3
  • 13

3 Answers3

0

I thought I checked the

If anyone else has this issue, you need to add short_open_tags = on to the php.ini file How to enable PHP short tags?

Community
  • 1
  • 1
Mark
  • 70
  • 3
  • 13
0

Given your later comments and followup code, I'm assuming that your original example would actually have worked rather than failed.

Your problem is that you're using short open tags. These will only work if PHP's short_open_tag option is set, which is the reason they're discouraged in the manual. If you're developing code for others—plugins or themes for WordPress, for example—you should avoid using short tags, as there's no guarantee a server will have short_open_tag set, and end users may not be able to turn them on.

Matt Gibson
  • 37,886
  • 9
  • 99
  • 128
0

Just to add for informational purposes. You don't need to abuse the php tags. Only use them when you are switching between html and php. You don't have to open and close php tags on every single line when you are working with pure php across

This line

<? wp_enqueue_script('jquery'); ?>

<? wp_enqueue_script('bootstrapcss'); ?>

<? wp_head(); ?>

can be simplified into

 <? 
   wp_enqueue_script('jquery');

   wp_enqueue_script('bootstrapcss');

   wp_head(); 
 ?>
Pieter Goosen
  • 9,768
  • 5
  • 35
  • 55