您可以使用以下内容:
function my_custom_shortcode( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
\'word\' => \'example\', // the word which will be replaced
\'part\' => \'1\' // for identifing the different texts
),
$atts,
\'textblock\'
);
// only if a word exists
if ( isset( $atts[\'word\'] ) ) {
// see if part="1" was inserted in the shortcode...
if ($atts[\'part\'] === \'1\') {
$text = \'Lorem ipsum dolor sit amet, \'.$atts[\'word\'].\' sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna \'.$atts[\'word\'].\' erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est \'.$atts[\'word\'].\' sit amet.\';
} else { //... if not use this text
$text = \'At vero eos et accusam et justo duo dolores et, \'.$atts[\'word\'].\'.\';
}
return $text; // return the text
}
}
add_shortcode( \'textblock\', \'my_custom_shortcode\' );
我们使用具有2个属性的短代码。一个属性是要替换的单词。第二个属性(part)用于标识要显示的静态文本
如您所见,这只适用于您之前在快捷码中输入的静态文本。