在 WordPress 编辑器添加“下一页”分页按钮

本文介绍如何在WordPress编辑器中轻松添加下一页按钮,通过简单的代码实现文章分页功能,适用于WP4.2及以上版本。

不少朋友总喜欢给长一点的文章进行分页,但是默认情况下,在WordPress的编辑器中,是没有显示“下一页”按钮的,每次都要手动添加分页代码 <!–nextpage–>是一件非常费力的事,其实,我们只要在当前主题的 functions.php 添加下面的代码,就可以显示“下一页”按钮啦:

如果你是 WP 4.2 或以上的版本,可以使用下面的代码:

1
2
3
4
5
6
7
8
9
10
11
/*-----------------------------------------------------------------------------------*/
# 在 WordPress 编辑器添加“下一页”按钮
# https://www.wpdaxue.com/add-next-page-button-wordpress-post-editor.html
/*-----------------------------------------------------------------------------------*/
add_filter( 'mce_buttons', 'cmp_add_page_break_button', 1, 2 );
function cmp_add_page_break_button( $buttons, $id ){
    if ( 'content' != $id )
        return $buttons;
    array_splice( $buttons, 13, 0, 'wp_page' );
    return $buttons;
}

效果如下:

2015-09-05_105422_wpdaxue_com

===以下为旧版本代码===========

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * 在 WordPress 编辑器添加“下一页”按钮
 * https://www.wpdaxue.com/add-next-page-button-wordpress-post-editor.html
 */
add_filter('mce_buttons','wpdaxue_add_next_page_button');
function wpdaxue_add_next_page_button($mce_buttons) {
	$pos = array_search('wp_more',$mce_buttons,true);
	if ($pos !== false) {
		$tmp_buttons = array_slice($mce_buttons, 0, $pos+1);
		$tmp_buttons[] = 'wp_page';
		$mce_buttons = array_merge($tmp_buttons, array_slice($mce_buttons, $pos+1));
	}
	return $mce_buttons;
}

最终效果如下图所示:

add-next-page-button-wpdaxue_com

转载于:https://my.oschina.net/u/1266171/blog/1930656

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值