[更改主题后,在许多文章中,我都使用了旧的简码。它包括<h2>
和<p>
。我想用相同的名称创建一个新的短代码,以重命名旧的短代码。我需要为<h2>
和<p>
使用不同的类。
我具有此功能:
function factoid_function( $atts, $content = null ) {
return '<div class="vf-box vf-box--normal vf-box-theme--primary | factoid-box">' . '<p class="vf-box__text">' . $content . '</p>' . '</div>';
}
add_shortcode('fact-box', 'factoid_function');
这是HTML输出。
<div class="vf-box vf-box--normal vf-box-theme--primary | factoid-box">
<p class="vf-box__text"></p>
<h2>What is mesoscopic imaging?</h2>
<p>Mesoscopic imaging involves looking at details of biological systems in the context of an organ, body part, or organism. It’s an approach that recognises that a heart, an arm, or a fish is more than just a set of cells. In any tissue, organ, or body part, cells are packed tightly together or arranged in relation to each other.
</p>
</div>
为什么$ content与类一起抛出在段落之外?
如何分割$ content以便为段落分配vf-box__text
并为h2分配vf-box__heading
?
提前感谢!
您必须对内容执行do_shortcode。并使用编辑器制作<h2>
和<p>
。将它们放在[fact-box]
和[/fact-box]
]之间
function factoid_function( $atts, $content = null ) {
$output = '<div class="vf-box vf-box--normal vf-box-theme--primary | factoid-box"><p class="vf-box__text">';
$output .= do_shortcode($content);
$output .='</p></div>';
return $output;
}
add_shortcode('fact-box', 'factoid_function');