-3

これは可能ですか?Title属性<div id="example" title="is possible put PHP code here?"> some text </div> を入れたい<?php the_excerpt(); ?>

4

1 に答える 1

1

はい。

<div id="example" title="<?php echo the_excerpt(); ?>"> some text </div>

また:

<div id="example" title="<?= the_excerpt() ?>"> some text </div>

後者は、PHP ブロック内のすべてを自動的にエコーする省略表現ですが、前者には、何かをエコーする (ブロックがある場所に出力する) コードを含む、任意のコードを含めることができます。

基本的な構文を参照してください。

ただし、HTML に出力するものはすべてエスケープして、それが有効な属性値であることを確認してください (the_excerpt()エスケープされた文字列が既に返されていない場合)。

<div id="example" title="<?= htmlspecialchars(the_excerpt()) ?>"> some text </div>
于 2012-05-25T11:13:57.867 に答える