php code inside html is being commented out

2019-06-05 13:17发布

My php code is called from the html code in a wordpress page. However It is being commented out by the browser. The code:

<?php if (function_exists (gCF)) gCF(); ?>

inside a div is being read as following (when I see in firebug or chrome)

<!--?php if (function_exists (gCF)) gCF(); ?-->

I searched the net and found following similar questions, but sadly there is no apt solution, and nor has anyone mentioned why this is happening. Is it because of doctype???

Question 1 Question 2 Question 3 Question 4

Thanks in advance.

3条回答
女痞
2楼-- · 2019-06-05 13:50

By default, Wordpress does not support the use of PHP code directly in a post. A simple Google search brought up some possible plugins that could allow you to do this.

查看更多
The star\"
3楼-- · 2019-06-05 13:56

It's possible that the file is not being parsed by PHP. Make sure the file extension is PHP or your server is setup to parse that filetype using PHP.

查看更多
够拽才男人
4楼-- · 2019-06-05 14:06

It sounds to me like the code is inside a file that does not have a .php extension and therefore the code is being evaluated as HTML.

If you want to use php in wordpress, make sure it's in a template file (either an existing one or one that you've made).

查看更多
登录 后发表回答