[wordpress] 文章或页面设置密码保护无效的问题

· PHP

如果不使用 the_content()get_the_content() 方法来展示文章或页面内容,那么在后台设置密码保护是无效的

通过 get_the_content()源码得知,该方法调用了一个叫 post_password_required( $_post ) 的方法进行密码判断,该方法是关键

所以,如果是自定义的页面或文章页面,最好使用 the_content()get_the_content() 方法来展示内容。

或者直接添加以下代码:

// If post password required and it doesn't match the cookie.
if ( post_password_required( $_post ) ) {
	return get_the_password_form( $_post );
}

发表评论