在 WordPress 中执行 PHP
我需要在每篇 WordPress 文章中运行一些代码。
问题是,默认情况下,WordPress 不会在帖子中执行任何 PHP。我尝试过很多插件(包括 ExecPHP 等)但没有效果。如何让 PHP 在 WordPress 中运行?
I need to run some code in every WordPress article.
The problem is, by default, WordPress does not execute any PHP in posts. I've tried a wealth of plugins (including ExecPHP and suchlike) but to no avail. How can I get PHP to run in WordPress?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
每篇文章的代码都一样吗?如果是这样,为什么不更改创建帖子的 WordPress 文件并在其中添加代码呢?
is it the same code for every article? if so why don't you change the wordpress file that creates the post and add the code in there?
这是很危险的,因为如果没有正确保护它可能会导致整个站点崩溃,但是您可以使用 php 函数 eval() 来执行 php 代码。
请参阅:
http://ca.php.net/manual/en/function.eval .php
This is dangerous as it can crash your entire site if it's not secured properly, but you may use the php function eval() to execute php code.
See:
http://ca.php.net/manual/en/function.eval.php
像这样:
完毕。
Goes like this:
Done.
您可以使用“PHP Code for posts”插件来实现此目的,启用此插件后,您将能够在 WordPress 编辑器中运行 php 代码,就像任何 php 编辑器一样,要运行您的 php 代码,您必须在 php 标签中编写代码。你可以从这里下载这个插件
https://wordpress.org/plugins/php-code -for-posts/
You can use "PHP Code for posts" plugin for this, after enable this plugin you will be able to run php code in wordpress editor like any php editor to run your php code you must write your code in php tags. you can download this plugin from here
https://wordpress.org/plugins/php-code-for-posts/
该插件将为您省去制作单独自定义插件的麻烦:
http://www.hitreach.co.uk/wordpress-plugins/allow-php-in-posts-and-pages/
然而,正如其他人所建议的那样,这确实可能会造成安全漏洞,因为它可能是这个代码将使用 eval()
This plugin will save you the hassle of having to make separate custom plugins:
http://www.hitreach.co.uk/wordpress-plugins/allow-php-in-posts-and-pages/
However as others have suggested this does potentially open security exploits as it's likely this code will utilise eval()