这可能吗? <div id="example" title="is possible put PHP code here?"> some text </div>
我希望将<?php the_excerpt(); ?>
放在Title属性
答案 0 :(得分:1)
是
<div id="example" title="<?php echo the_excerpt(); ?>"> some text </div>
或:
<div id="example" title="<?= the_excerpt() ?>"> some text </div>
后者是一种自动回显PHP块中所有内容的简写,而前者可以包含任何代码,包括回显某些内容的代码(将其打印到块所在的位置)。
请参阅basic syntax。
但请注意,要将您输出的任何内容转义为HTML,以确保它是有效的属性值(除非the_excerpt()
已经返回转义字符串):
<div id="example" title="<?= htmlspecialchars(the_excerpt()) ?>"> some text </div>