【发布时间】:2021-10-17 15:37:29
【问题描述】:
我正在尝试注册 WordPress 短代码。
我有一个包含 HTML 的 PHP 返回语句。在 HTML 中,我有一个 javascript onclick 函数。 Visual Studio Code 抛出语法错误,即意外的“帧”(T_STRING),需要“,”或“;”
我已阅读有关 Stack Overflow 的其他文章,并尝试转义字符串内的单引号,但我可能会不准确地转义。下面是一些没有任何转义的原始代码。
我知道下面的代码可能不漂亮,但仍然感谢所有帮助。
<?php
function torque_hello_world_shortcode() {
return '<div class="description pagecontent simple"></div>
<a onclick="document.getElementById('frame').style.display = document.getElementById('frame').style.display == 'none' ? 'block' : 'none'; return false;"><img class="someclass" src="#" alt="alt text" style="width:60px;height:60px;cursor:pointer !important;">
<p class="something" style="cursor:pointer !important;">text! <span class="otherclass" style="cursor:pointer !important;">more text</span></p></a>
<div class="description pagecontent simple"></div>';
}
add_shortcode( 'helloworld', 'torque_hello_world_shortcode' );
【问题讨论】: