我正在使用 wordpress 作为我们公司网站的 CMS。我们有大约 5-10 个页面,我们希望在其中插入相同的号召性用语内容。
如何创建允许我将帖子中的内容嵌入页面的简码?
谢谢史蒂文。
我没有对此进行测试,但您可能需要以下内容:
function create_call_to_action_shortcode( $atts ) {
$call_to_action_content = '';
$query = new WP_Query( array( 'p' => $post_id, 'no_found_rows' => true ) );
if( $query->have_posts() ) {
$query->the_post();
remove_filter( 'the_content', 'sharing_display', 19);
$call_to_action_content = apply_filters( 'the_content', get_the_content() );
add_filter( 'the_content', 'sharing_display', 19);
wp_reset_postdata();
}
return $call_to_action_content;
}
add_shortcode( 'call_to_action', 'create_call_to_action_shortcode' );`
在您的页面(或其他帖子)中,您可以简单地插入[call_to_action]
页面/帖子内容。
您可以在此处找到有关 shorcode 的更多信息。:)
编辑:
为了从帖子内容中删除共享按钮,您需要调用remove_filter( 'the_content', 'sharing_display', 19);
. 我已经更新了上面的代码。