我是php新手。我有以下行在我的WordPress网站的函数。php文件。我认为我格式化get_the_bag
的方式有问题。谁能告诉我出了什么事?
$output .= "<span class='bag-item'>. get_the_bag(); .</span>";
去掉get_the_bag()
后面的分号,并在第一个span之后和第二个span之前加上标记:
$output .= "<span class='bag-item'>". get_the_bag() ."</span>";
- 你把各种连接的东西和一个函数调用放到字符串的中间
- 在函数调用 后终止语句(使用
;
)你想:
$output .= sprintf("<span class='bag-item'>%s</span>", get_the_bag());
或
$output .= "<span class='bag-item'>" . get_the_bag() . "</span>";
(都假设get_the_bag
返回一个HTML安全字符串。如果没有,则需要用htmlspecialchars
)包装该函数调用。
try this
$output .= "<span class='bag-item'>" . get_the_bag() . "</span>";