在短代码属性值中使用连字符安全吗?
例如:
[foo something="fo-bar"]
在短代码属性值中使用连字符安全吗?
例如:
[foo something="fo-bar"]
它很安全,你使用它不会有任何问题,唯一要注意的是Hyphens 和Shortcodes 来自Codex.
在短代码名称中使用连字符时要小心。在以下情况下,WordPress可能会看到第二个开头短代码与第一个相同(基本上WordPress会看到连字符前面的第一部分):
[tag]
[tag-a]
这完全取决于首先定义哪个短代码。如果要使用连字符,请首先定义最短的短代码。要避免这种情况,请使用下划线或无分隔符:
[tag_a]
tl;dr; 破折号(连字符)-
在短代码中使用是安全的attribute values.
快捷码属性值规则:快捷码attribute values, 任何东西other than the following 四个通常可以:
不应该有任何方括号[
或]
, e、 g。[foo bar=\'baa]z\']
[foo bar=\'baa\'z\'][foo bar="baa"z"]\\ 将被逃脱
// dash or hyphen is fine
[foo bar=\'baa-z\']
// Double quote within single quote is fine
[foo bar=\'baa"z\']
// single quote within double quote is fine
[foo bar="baa\'z"]
// space is fine
[foo bar=\'baa z\']
// use double back slash to get single back slash
[foo bar=\'baa\\\\z\']
引用自codex:属性值不得包含以下字符:方括号:[ ]
报价:" \'
无引号的值也不得包含空格。
HTML字符<
和>
对属性的支持有限。
建议使用HTML编码来转义短代码属性中的特殊字符。最重要的是,出现在shortcode属性中的任何用户输入都必须转义或去除特殊字符。
请注意,允许在单引号值内使用双引号,反之亦然,但在处理用户输入时,不建议使用双引号。
下列字符如果未在属性值内转义,将自动剥离并转换为空格:
无中断空间:\\xC2\\xA0
零宽度空间:\\xE2\\x80\\x8B
我不能对foreach使用shortcode。它给了我语法错误。我错在哪里?function create_galeri_shortcode($atts) { $atts = shortcode_atts( array( ), $atts, \'galeri\' ); if ( has_post_format( \'gallery\' )) { $images = get_post_