如何在短代码中传递ID

【如何在短代码中传递ID】我需要修改主题的短代码之一, 以便可以将类ID传递给列。我需要能够输入一个额外的参数id =” ” , 然后输入任何ID。
这些是简码:

if (!function_exists('two_col_50_50_col1')) { function two_col_50_50_col1($atts, $content = null) { return '< div class="two_columns_50_50 clearfix"> < div class="column1"> < div class="column_inner"> ' . do_shortcode($content).'< /div> < /div> '; } } add_shortcode('two_col_50_50_col1', 'two_col_50_50_col1'); if (!function_exists('two_col_50_50_col2')) { function two_col_50_50_col2($atts, $content = null) { return '< div class="column2"> < div class="column_inner"> ' . do_shortcode($content) . '< /div> < /div> < /div> '; } } add_shortcode('two_col_50_50_col2', 'two_col_50_50_col2');

#1你可以将参数传递给短代码, 如下所示:
// [bartag foo="foo-value"] function bartag_func( $atts ) { $a = shortcode_atts( array( 'foo' => 'something', 'bar' => 'something else', ), $atts ); return "foo = {$a['foo']}"; } add_shortcode( 'bartag', 'bartag_func' );

因此, 对于你的代码, 它就像:
if (!function_exists('two_col_50_50_col1')) { function two_col_50_50_col1($atts, $content = null) { $a = shortcode_atts( array( 'id' => '' ), $atts ); return '< div class="two_columns_50_50 clearfix '.$a['id'].'"> < div class="column1"> < div class="column_inner"> ' . do_shortcode($content).'< /div> < /div> '; } } add_shortcode('two_col_50_50_col1', 'two_col_50_50_col1'); if (!function_exists('two_col_50_50_col2')) { function two_col_50_50_col2($atts, $content = null) { $a = shortcode_atts( array( 'id' => '' ), $atts ); return '< div class="column2 '.$a['id'].'"> < div class="column_inner"> ' .do_shortcode($content) . '< /div> < /div> < /div> '; } } add_shortcode('two_col_50_50_col2', 'two_col_50_50_col2');

你可以像这样调用短代码:
[two_col_50_50_col2 id="something"]

有关wordpress短代码的详细信息, 请阅读以下文档:https://codex.wordpress.org/Shortcode_API

    推荐阅读