试图在声明周围回应H2标签

use*_*833 0 html php wordpress

我想要一个包含在h2标签中的标题声明.我期待这很简单,但它在标题之后回应了h2标签.它以下列方式显示:

我正在使用的代码:

echo "<h2>".the_title()."</h2>";
Run Code Online (Sandbox Code Playgroud)

结果:

title
<h2></h2>
Run Code Online (Sandbox Code Playgroud)

如何更正此行为并确保h2标记之间的回显标题结束?

Abr*_*ver 7

我讨厌WordPress.您有几个选项http://codex.wordpress.org/Function_Reference/the_title:

the_title('<h2>', '</h2>', true);
Run Code Online (Sandbox Code Playgroud)

要么:

echo "<h2>" . the_title(null, null, false) . "</h2>";
Run Code Online (Sandbox Code Playgroud)

http://codex.wordpress.org/Function_Reference/get_the_title:

echo "<h2>" . get_the_title() . "</h2>";
Run Code Online (Sandbox Code Playgroud)