首页 > 解决方案 > 当我在我的 html 网站上输入 {page_title} 时,有没有办法打印网页标题?

问题描述

我正在 Wordpress 上创建一个网站,我必须为每个美国州(例如 domain.com/Alabama)制作 50 页,我想为每个州键入一个更改为“Alabama”的变量等等,所以我想要针对变量打印页面标题。(例如,如果我<h2>Services in {page_title}</h2>在此页面上键入“domain.com/Alabama”,它应该给我“阿拉巴马州的服务”)

我正在尝试这个get_the_title( int|WP_Post $post )

我得到空白空间...

标签: phpwordpress

解决方案


如果你在循环中,你可以使用:

the_title();

https://codex.wordpress.org/Function_Reference/the_title


推荐阅读