您可以在回调函数中传递属性数组($atts),该函数将在运行add\\u shortcode()时运行。
请注意$user_defined_attributes
在以下示例中:
add_shortcode( \'faq\', \'process_the_faq_shortcode\' );
/**
* Process the FAQ Shortcode to build a list of FAQs.
*
* @since 1.0.0
*
* @param array|string $user_defined_attributes User defined attributes for this shortcode instance
* @param string|null $content Content between the opening and closing shortcode elements
* @param string $shortcode_name Name of the shortcode
*
* @return string
*/
function process_the_faq_shortcode( $user_defined_attributes, $content, $shortcode_name ) {
$attributes = shortcode_atts(
array(
\'number_of_faqs\' => 10,
\'class\' => \'\',
),
$user_defined_attributes,
$shortcode_name
);
// do the processing
// Call the view file, capture it into the output buffer, and then return it.
ob_start();
include( __DIR__ . \'/views/faq-shortcode.php\' );
return ob_get_clean();
}
参考号:
hellofromtonya