且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在WordPress页面中插入PHP代码并发布

更新时间:2023-12-01 22:40:58

默认情况下,WordPress不会在帖子/页面内容中执行PHP,除非它具有简码.

WordPress does not execute PHP in post/page content by default unless it has a shortcode.

最快,最简单的方法是使用一个插件,该插件可让您运行嵌入在帖子内容中的PHP.

The quickest and easiest way to do this is to use a plugin that allows you to run PHP embedded in post content.

还有另外两种快速简便"的方法无需插件即可完成:

There are two other "quick and easy" ways to accomplish it without a plugin:

  • 为其输入简码(将其放入functions.php并与国家/地区名称相呼应),这非常容易-参见此处:

  • Make it a shortcode (put it in functions.php and have it echo the country name) which is very easy - see here: Shortcode API at WP Codex

将其放入模板文件-根据您的默认页面模板为该页面创建自定义模板,然后将PHP添加到模板文件而不是帖子内容中:自定义页面模板

Put it in a template file - make a custom template for that page based on your default page template and add the PHP into the template file rather than the post content: Custom Page Templates