[英]wordpress header.php not accepting php
創建wordpress自定義主題時,我遇到了一個奇怪的問題。 由於某些原因
hello <?php echo 'world'; ?>
顯示為html
hello <?php echo 'world'; ?>
代替
hello world
之前,我已經創建了很多wordpress網站,但這是亞馬遜服務器上的第一個網站。非常感謝您的幫助。 標記
網站是lmof.uk/demo
header.php(盡可能多的stackoverflow讓我發布)
<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">
我以為我檢查了
如果還有其他人遇到此問題,則需要將short_open_tags = on添加到php.ini文件中。 如何啟用PHP短標簽?
考慮到您以后的評論和后續代碼,我假設您的原始示例實際上是有效的,而不是失敗的。
您的問題是您使用的是短標簽。 只有在設置了PHP的short_open_tag選項的情況下,這些選項才起作用,這是手冊中不鼓勵使用它們的原因。 如果您正在為其他人(例如WordPress的插件或主題)開發代碼,則應避免使用短標簽,因為不能保證服務器將設置short_open_tag
,並且最終用戶可能無法打開它們。
僅供參考。 您不需要濫用php標簽。 僅當在html和php之間切換時才使用它們。 使用純php時,不必在每一行上都打開和關閉php標簽。
這條線
<? wp_enqueue_script('jquery'); ?>
<? wp_enqueue_script('bootstrapcss'); ?>
<? wp_head(); ?>
可以簡化成
<?
wp_enqueue_script('jquery');
wp_enqueue_script('bootstrapcss');
wp_head();
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.