我有一个函数:
/**
* is_edit_page
* function to check if the current page is a post edit page
*
* @author Ohad Raz <[email protected]>
*
* @param string $new_edit what page to check for accepts new - new post page ,edit - edit post page, null for either
* @return boolean
*/
function is_edit_page($new_edit = null){
global $pagenow;
//make sure we are on the backend
if (!is_admin()) return false;
if($new_edit == "edit")
return in_array( $pagenow, array( \'post.php\', ) );
elseif($new_edit == "new") //check for new post page
return in_array( $pagenow, array( \'post-new.php\' ) );
else //check for either new or edit
return in_array( $pagenow, array( \'post.php\', \'post-new.php\' ) );
}
Usage与任何其他条件标记一样,用法很简单,很少有示例:
检查新页面或编辑页面:
if (is_edit_page()){
//yes its an edit/new post page
}
检查新帖子页面:
if (is_edit_page(\'new\')){
//yes its an new post page
}
检查编辑帖子页面:
if (is_edit_page(\'edit\')){
//yes its an existing post page
}
将此与
$typenow
要检查特定帖子类型编辑页面,请执行全局操作:
global $typenow;
if (is_edit_page(\'edit\') && "Post_Type_Name" == $typenow){
//yes its an edit page of a custom post type named Post_Type_Name
}