统计了历年的wordpress 的官方主题,一共统计了 13 个,这 13个 主题中使用的函数,总结了一下。这些函数对制作模板来说,很重要。

🎨 主题相关函数
https://www.wpzhan.com/static/html/wordpress-theme-functions.html
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
get_header( $name ) | $name (string) – 模板部分名称 | void | 加载头部模板 |
get_footer( $name ) | $name (string) – 模板部分名称 | void | 加载底部模板 |
get_sidebar( $name ) | $name (string) – 模板部分名称 | void | 加载侧边栏模板 |
get_template_part( $slug, $name ) | $slug (string) – 模板段, $name (string) – 特定名称 | void | 加载指定的模板部分 |
get_template_directory() | 无 | string | 获取当前主题目录路径 |
get_template_directory_uri() | 无 | string | 获取当前主题目录URL |
get_stylesheet_directory() | 无 | string | 获取子主题目录路径 |
get_stylesheet_directory_uri() | 无 | string | 获取子主题目录URL |
get_stylesheet_uri() | 无 | string | 获取主样式表URL |
get_theme_mod( $name, $default ) | $name (string) – 主题修改项, $default (mixed) – 默认值 | mixed | 获取主题修改值 |
set_theme_mod( $name, $value ) | $name (string) – 主题修改项, $value (mixed) – 设置值 | bool | 设置主题修改值 |
add_theme_support( $feature ) | $feature (string) – 功能名称 | bool | 添加主题功能支持 |
current_theme_supports( $feature ) | $feature (string) – 功能名称 | bool | 检查当前主题是否支持某功能 |
get_theme_support( $feature ) | $feature (string) – 功能名称 | mixed|false | 获取主题支持的功能配置 |
register_nav_menu( $location, $description ) | $location (string) – 菜单位置, $description (string) – 描述 | void | 注册一个导航菜单 |
register_nav_menus( $locations ) | $locations (array) – 菜单位置数组 | void | 注册多个导航菜单 |
has_nav_menu( $location ) | $location (string) – 菜单位置 | bool | 检查是否有指定位置的菜单 |
wp_nav_menu( $args ) | $args (array) – 菜单参数 | string|void | 显示导航菜单 |
register_sidebar( $args ) | $args (array) – 侧边栏参数 | string | 注册侧边栏 |
dynamic_sidebar( $index ) | $index (string|int) – 侧边栏ID | bool | 显示动态侧边栏 |
is_active_sidebar( $index ) | $index (string|int) – 侧边栏ID | bool | 检查侧边栏是否激活 |
add_image_size( $name, $width, $height, $crop ) | $name (string) – 尺寸名称, $width (int) – 宽度, $height (int) – 高度, $crop (bool|array) – 裁剪方式 | void | 添加新的图片尺寸 |
set_post_thumbnail_size( $width, $height, $crop ) | $width (int) – 宽度, $height (int) – 高度, $crop (bool|array) – 裁剪方式 | void | 设置特色图片尺寸 |
body_class( $class ) | $class (string|array) – 额外的类名 | void | 输出body类名 |
post_class( $class, $post_id ) | $class (string|array) – 额外的类名, $post_id (int) – 文章ID | void | 输出文章类名 |
wp_body_open() | 无 | void | 触发body打开钩子 |
wp_footer() | 无 | void | 触发底部钩子 |
wp_head() | 无 | void | 触发头部钩子 |
📝 文章/内容相关函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
the_title( $before, $after, $echo ) | $before (string) – 前缀, $after (string) – 后缀, $echo (bool) – 是否直接输出 | string|void | 显示文章标题 |
get_the_title( $post ) | $post (int|WP_Post) – 文章ID或对象 | string | 获取文章标题 |
the_content( $more_link_text, $strip_teaser ) | $more_link_text (string) – 更多链接文本, $strip_teaser (bool) – 是否剥离摘要 | void | 显示文章内容 |
get_the_content( $more_link_text, $strip_teaser, $post ) | $more_link_text (string) – 更多链接文本, $strip_teaser (bool) – 是否剥离摘要, $post (int|WP_Post) – 文章 | string | 获取文章内容 |
the_excerpt() | 无 | void | 显示文章摘要 |
get_the_excerpt( $post ) | $post (int|WP_Post) – 文章 | string | 获取文章摘要 |
has_excerpt( $post ) | $post (int|WP_Post) – 文章 | bool | 检查是否有自定义摘要 |
the_permalink() | 无 | void | 显示文章永久链接 |
get_permalink( $post, $leavename ) | $post (int|WP_Post) – 文章, $leavename (bool) – 是否保留名称 | string|false | 获取文章永久链接 |
the_post_thumbnail( $size, $attr ) | $size (string|array) – 图片尺寸, $attr (array) – 图片属性 | void | 显示文章特色图片 |
get_the_post_thumbnail( $post, $size, $attr ) | $post (int|WP_Post) – 文章, $size – 尺寸, $attr – 属性 | string | 获取文章特色图片 |
has_post_thumbnail( $post ) | $post (int|WP_Post) – 文章 | bool | 检查是否有特色图片 |
get_post_thumbnail_id( $post ) | $post (int|WP_Post) – 文章 | int | 获取特色图片ID |
the_date( $format, $before, $after, $echo ) | $format (string) – 日期格式, $before (string) – 前缀, $after (string) – 后缀, $echo (bool) – 是否输出 | string|void | 显示文章发布日期 |
get_the_date( $format, $post ) | $format (string) – 日期格式, $post (int|WP_Post) – 文章 | string | 获取文章发布日期 |
the_time( $format ) | $format (string) – 时间格式 | void | 显示文章发布时间 |
get_the_time( $format, $post ) | $format (string) – 时间格式, $post – 文章 | string | 获取文章发布时间 |
the_modified_date( $format, $before, $after, $echo ) | 同上 | string|void | 显示文章修改日期 |
get_the_modified_date( $format, $post ) | $format – 日期格式, $post – 文章 | string | 获取文章修改日期 |
the_author() | 无 | void | 显示文章作者 |
get_the_author( $post ) | $post (int|WP_Post) – 文章 | string | 获取文章作者名 |
the_author_meta( $field, $user_id ) | $field (string) – 字段名, $user_id (int) – 用户ID | void | 显示作者元数据 |
get_the_author_meta( $field, $user_id ) | $field – 字段名, $user_id – 用户ID | string | 获取作者元数据 |
the_category( $separator, $parents, $post_id ) | $separator – 分隔符, $parents – 父级显示方式, $post_id – 文章ID | void | 显示文章分类 |
get_the_category_list( $separator, $parents, $post_id ) | 同上 | string | 获取文章分类列表 |
in_category( $category, $post ) | $category (mixed) – 分类, $post – 文章 | bool | 检查文章是否在指定分类中 |
the_tags( $before, $sep, $after ) | $before – 前缀, $sep – 分隔符, $after – 后缀 | void | 显示文章标签 |
get_the_tag_list( $before, $sep, $after, $post_id ) | 同上 | string|false | 获取文章标签列表 |
has_tag( $tag, $post ) | $tag (mixed) – 标签, $post – 文章 | bool | 检查文章是否有指定标签 |
the_terms( $post_id, $taxonomy, $before, $sep, $after ) | $post_id – 文章ID, $taxonomy – 分类法, $before – 前缀, $sep – 分隔符, $after – 后缀 | void | 显示文章术语 |
has_term( $term, $taxonomy, $post ) | $term – 术语, $taxonomy – 分类法, $post – 文章 | bool | 检查是否有指定术语 |
wp_link_pages( $args ) | $args (array) – 参数数组 | void | 显示文章分页链接 |
🔄 循环相关函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
have_posts() | 无 | bool | 检查是否有文章 |
the_post() | 无 | void | 设置当前文章 |
rewind_posts() | 无 | void | 重置循环到开始 |
wp_reset_query() | 无 | void | 重置主查询 |
wp_reset_postdata() | 无 | void | 重置文章数据 |
in_the_loop() | 无 | bool | 检查是否在主循环内 |
get_queried_object() | 无 | WP_Term|WP_Post|WP_User|null | 获取当前查询对象 |
get_queried_object_id() | 无 | int | 获取当前查询对象ID |
get_query_var( $var, $default ) | $var – 变量名, $default – 默认值 | mixed | 获取查询变量 |
set_query_var( $var, $value ) | $var – 变量名, $value – 变量值 | void | 设置查询变量 |
💬 评论相关函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
comments_template( $file, $separate_comments ) | $file – 模板文件, $separate_comments – 是否分离评论 | void | 加载评论模板 |
comments_number( $zero, $one, $more ) | $zero – 0条评论文本, $one – 1条评论文本, $more – 多条评论文本 | void | 显示评论数量 |
get_comments_number( $post_id ) | $post_id (int) – 文章ID | int | 获取评论数量 |
comment_form( $args, $post_id ) | $args – 参数数组, $post_id – 文章ID | void | 显示评论表单 |
wp_list_comments( $args, $comments ) | $args – 参数数组, $comments – 评论数组 | void | 显示评论列表 |
comments_open( $post_id ) | $post_id (int) – 文章ID | bool | 检查评论是否开放 |
pings_open( $post_id ) | $post_id (int) – 文章ID | bool | 检查Pingback是否开放 |
get_comment_pages_count( $comments, $per_page, $threaded ) | $comments – 评论数组, $per_page – 每页数量, $threaded – 是否嵌套 | int | 获取评论分页数 |
paginate_comments_links( $args ) | $args – 参数数组 | string|void | 显示评论分页链接 |
previous_comments_link( $label ) | $label – 链接文本 | void | 显示上一页评论链接 |
next_comments_link( $label ) | $label – 链接文本 | void | 显示下一页评论链接 |
get_comment_author() | 无 | string | 获取当前评论作者 |
get_comment_date( $format, $comment ) | $format – 日期格式, $comment – 评论对象 | string | 获取评论日期 |
get_comment_time( $format, $comment ) | $format – 时间格式, $comment – 评论对象 | string | 获取评论时间 |
comment_reply_link( $args ) | $args – 参数数组 | string|void | 显示评论回复链接 |
edit_comment_link( $text, $before, $after ) | $text – 链接文本, $before – 前缀, $after – 后缀 | void | 显示编辑评论链接 |
👤 用户相关函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
is_user_logged_in() | 无 | bool | 检查用户是否登录 |
wp_get_current_user() | 无 | WP_User | 获取当前用户对象 |
get_current_user_id() | 无 | int | 获取当前用户ID |
current_user_can( $capability, $args ) | $capability – 权限, $args – 附加参数 | bool | 检查用户权限 |
wp_login_form( $args ) | $args (array) – 登录表单参数 | void | 显示登录表单 |
wp_loginout( $redirect ) | $redirect – 重定向URL | void | 显示登录/退出链接 |
wp_register( $before, $after ) | $before – 前缀, $after – 后缀 | void | 显示注册链接 |
wp_logout_url( $redirect ) | $redirect – 重定向URL | string | 获取退出登录URL |
wp_lostpassword_url( $redirect ) | $redirect – 重定向URL | string | 获取找回密码URL |
get_userdata( $user_id ) | $user_id (int) – 用户ID | WP_User|false | 获取用户数据 |
get_user_meta( $user_id, $key, $single ) | $user_id – 用户ID, $key – 元数据键, $single – 是否返回单个值 | mixed | 获取用户元数据 |
get_avatar( $id_or_email, $size, $default, $alt, $args ) | $id_or_email – 用户ID或邮箱, $size – 头像尺寸 | string|false | 获取头像HTML |
wp_signon( $credentials, $secure_cookie ) | $credentials – 登录凭证, $secure_cookie – 安全Cookie | WP_User|WP_Error | 用户登录 |
🎯 条件标签函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
is_home() | 无 | bool | 判断是否为博客首页 |
is_front_page() | 无 | bool | 判断是否为网站首页 |
is_single( $post ) | $post (mixed) – 文章ID、slug或对象 | bool | 判断是否为单篇文章页 |
is_page( $page ) | $page (mixed) – 页面ID、slug或标题 | bool | 判断是否为页面 |
is_singular( $post_types ) | $post_types – 文章类型 | bool | 判断是否为单一文章类型页 |
is_archive() | 无 | bool | 判断是否为归档页 |
is_category( $category ) | $category – 分类ID、slug或名称 | bool | 判断是否为分类页 |
is_tag( $tag ) | $tag – 标签ID、slug或名称 | bool | 判断是否为标签页 |
is_tax( $taxonomy, $term ) | $taxonomy – 分类法, $term – 术语 | bool | 判断是否为自定义分类页 |
is_author( $author ) | $author – 作者ID、邮箱或昵称 | bool | 判断是否为作者页 |
is_date() | 无 | bool | 判断是否为日期归档页 |
is_year() | 无 | bool | 判断是否为年度归档页 |
is_month() | 无 | bool | 判断是否为月度归档页 |
is_day() | 无 | bool | 判断是否为日度归档页 |
is_time() | 无 | bool | 判断是否为时间归档页 |
is_new_day() | 无 | bool | 判断是否为新的一天 |
is_search() | 无 | bool | 判断是否为搜索结果页 |
is_404() | 无 | bool | 判断是否为404页 |
is_paged() | 无 | bool | 判断是否为分页页 |
is_preview() | 无 | bool | 判断是否为预览模式 |
is_sticky( $post_id ) | $post_id (int) – 文章ID | bool | 判断文章是否置顶 |
is_attachment( $attachment ) | $attachment – 附件ID或对象 | bool | 判断是否为附件页 |
is_feed() | 无 | bool | 判断是否为Feed |
is_admin() | 无 | bool | 判断是否为后台页面 |
is_multi_author() | 无 | bool | 判断是否为多作者站点 |
is_multisite() | 无 | bool | 判断是否为多站点网络 |
is_main_site() | 无 | bool | 判断是否为主站点 |
is_super_admin( $user_id ) | $user_id (int) – 用户ID | bool | 判断是否为超级管理员 |
is_child_theme() | 无 | bool | 判断是否使用子主题 |
is_page_template( $template ) | $template – 模板文件名 | bool | 判断是否使用特定页面模板 |
is_post_type_archive( $post_types ) | $post_types – 文章类型 | bool | 判断是否为文章类型归档页 |
is_post_type_hierarchical( $post_type ) | $post_type – 文章类型 | bool | 判断文章类型是否为层级结构 |
taxonomy_exists( $taxonomy ) | $taxonomy – 分类法名称 | bool | 检查分类法是否存在 |
is_rtl() | 无 | bool | 判断是否为从右到左语言 |
⚡ 钩子/动作/过滤器函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
add_action( $hook_name, $callback, $priority, $accepted_args ) | $hook_name – 钩子名, $callback – 回调函数, $priority – 优先级, $accepted_args – 接受参数数量 | true | 添加动作钩子 |
remove_action( $hook_name, $callback, $priority ) | $hook_name – 钩子名, $callback – 回调函数, $priority – 优先级 | bool | 移除动作钩子 |
do_action( $hook_name, ...$arg ) | $hook_name – 钩子名, ...$arg – 传递给钩子的参数 | void | 执行动作钩子 |
add_filter( $hook_name, $callback, $priority, $accepted_args ) | $hook_name – 过滤器名, $callback – 回调函数, $priority – 优先级, $accepted_args – 接受参数数量 | true | 添加过滤器钩子 |
remove_filter( $hook_name, $callback, $priority ) | $hook_name – 过滤器名, $callback – 回调函数, $priority – 优先级 | bool | 移除过滤器钩子 |
apply_filters( $hook_name, $value, ...$args ) | $hook_name – 过滤器名, $value – 要过滤的值, ...$args – 附加参数 | mixed | 应用过滤器钩子 |
add_shortcode( $tag, $callback ) | $tag – 短代码名称, $callback – 回调函数 | void | 添加短代码 |
remove_shortcode( $tag ) | $tag – 短代码名称 | void | 移除短代码 |
do_shortcode( $content, $ignore_html ) | $content – 要解析的内容, $ignore_html – 是否忽略HTML | string | 解析短代码 |
shortcode_parse_atts( $text ) | $text – 短代码属性字符串 | array | 解析短代码属性 |
🔧 选项/设置函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
get_option( $option, $default ) | $option – 选项名, $default – 默认值 | mixed | 获取选项值 |
update_option( $option, $value, $autoload ) | $option – 选项名, $value – 选项值, $autoload – 是否自动加载 | bool | 更新选项 |
add_option( $option, $value, $deprecated, $autoload ) | $option – 选项名, $value – 选项值, $deprecated – 已废弃, $autoload – 是否自动加载 | bool | 添加选项 |
delete_option( $option ) | $option – 选项名 | bool | 删除选项 |
get_transient( $transient ) | $transient – 临时数据名 | mixed|false | 获取临时数据 |
set_transient( $transient, $value, $expiration ) | $transient – 临时数据名, $value – 值, $expiration – 过期时间 | bool | 设置临时数据 |
delete_transient( $transient ) | $transient – 临时数据名 | bool | 删除临时数据 |
register_setting( $option_group, $option_name, $args ) | $option_group – 选项组, $option_name – 选项名, $args – 参数 | void | 注册设置 |
🌐 URL/路径相关函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
home_url( $path, $scheme ) | $path – 路径, $scheme – URL方案 | string | 获取网站URL |
site_url( $path, $scheme ) | $path – 路径, $scheme – URL方案 | string | 获取站点URL |
admin_url( $path, $scheme ) | $path – 路径, $scheme – URL方案 | string | 获取后台URL |
content_url( $path ) | $path – 路径 | string | 获取内容目录URL |
includes_url( $path ) | $path – 路径 | string | 获取包含目录URL |
plugins_url( $path, $plugin ) | $path – 路径, $plugin – 插件文件 | string | 获取插件目录URL |
wp_upload_dir() | 无 | array | 获取上传目录信息 |
wp_get_attachment_url( $attachment_id ) | $attachment_id (int) – 附件ID | string|false | 获取附件URL |
wp_get_attachment_image_url( $attachment_id, $size ) | $attachment_id – 附件ID, $size – 图片尺寸 | string|false | 获取附件图片URL |
wp_get_attachment_image( $attachment_id, $size, $icon, $attr ) | $attachment_id – 附件ID, $size – 尺寸, $icon – 是否使用图标, $attr – 属性 | string | 获取附件图片HTML |
wp_get_attachment_metadata( $attachment_id ) | $attachment_id (int) – 附件ID | array|false | 获取附件元数据 |
wp_attachment_is_image( $attachment_id ) | $attachment_id (int) – 附件ID | bool | 检查附件是否为图片 |
🔒 安全/清理函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
esc_html( $text ) | $text (string) – 要转义的文本 | string | 转义HTML内容 |
esc_attr( $text ) | $text (string) – 要转义的文本 | string | 转义HTML属性 |
esc_url( $url, $protocols, $_context ) | $url – URL, $protocols – 允许的协议, $_context – 上下文 | string | 转义URL |
esc_js( $text ) | $text (string) – 要转义的文本 | string | 转义JavaScript |
esc_textarea( $text ) | $text (string) – 要转义的文本 | string | 转义文本域内容 |
esc_url_raw( $url, $protocols ) | $url – URL, $protocols – 允许的协议 | string | 转义原始URL(用于数据库存储) |
wp_kses( $string, $allowed_html, $allowed_protocols ) | $string – 内容, $allowed_html – 允许的HTML, $allowed_protocols – 允许的协议 | string | 过滤HTML内容 |
wp_kses_post( $data ) | $data (string) – 内容 | string | 过滤文章内容的HTML |
wp_strip_all_tags( $string, $remove_breaks ) | $string – 字符串, $remove_breaks – 是否移除换行 | string | 移除所有HTML标签 |
sanitize_text_field( $str ) | $str (string) – 要清理的字符串 | string | 清理文本字段 |
sanitize_email( $email ) | $email (string) – 邮箱地址 | string | 清理邮箱地址 |
sanitize_file_name( $filename ) | $filename (string) – 文件名 | string | 清理文件名 |
sanitize_key( $key ) | $key (string) – 键名 | string | 清理键名 |
sanitize_title( $title, $fallback_title, $context ) | $title – 标题, $fallback_title – 备用标题, $context – 上下文 | string | 清理为URL友好的标题 |
sanitize_hex_color( $color ) | $color (string) – 颜色值 | string|null | 清理十六进制颜色 |
sanitize_hex_color_no_hash( $color ) | $color (string) – 无#的颜色值 | string|null | 清理无哈希的十六进制颜色 |
🌍 国际化/翻译函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
__( $text, $domain ) | $text – 要翻译的文本, $domain – 文本域 | string | 获取翻译文本 |
_e( $text, $domain ) | $text – 要翻译的文本, $domain – 文本域 | void | 输出翻译文本 |
_x( $text, $context, $domain ) | $text – 文本, $context – 上下文, $domain – 文本域 | string | 获取带上下文的翻译 |
_ex( $text, $context, $domain ) | $text – 文本, $context – 上下文, $domain – 文本域 | void | 输出带上下文的翻译 |
_n( $single, $plural, $number, $domain ) | $single – 单数, $plural – 复数, $number – 数量, $domain – 文本域 | string | 获取单复数翻译 |
_nx( $single, $plural, $number, $context, $domain ) | $single – 单数, $plural – 复数, $number – 数量, $context – 上下文, $domain – 文本域 | string | 获取带上下文的单复数翻译 |
esc_html__( $text, $domain ) | $text – 文本, $domain – 文本域 | string | 获取并转义HTML翻译 |
esc_html_e( $text, $domain ) | $text – 文本, $domain – 文本域 | void | 输出并转义HTML翻译 |
esc_attr__( $text, $domain ) | $text – 文本, $domain – 文本域 | string | 获取并转义属性翻译 |
esc_attr_e( $text, $domain ) | $text – 文本, $domain – 文本域 | void | 输出并转义属性翻译 |
esc_html_x( $text, $context, $domain ) | $text – 文本, $context – 上下文, $domain – 文本域 | string | 获取带上下文的转义HTML翻译 |
esc_attr_x( $text, $context, $domain ) | $text – 文本, $context – 上下文, $domain – 文本域 | string | 获取带上下文的转义属性翻译 |
load_theme_textdomain( $domain, $path ) | $domain – 文本域, $path – 路径 | bool | 加载主题翻译文件 |
load_child_theme_textdomain( $domain, $path ) | $domain – 文本域, $path – 路径 | bool | 加载子主题翻译文件 |
get_locale() | 无 | string | 获取当前语言环境 |
📱 媒体/附件函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
wp_get_archives( $args ) | $args (array) – 归档参数 | void | 显示文章归档 |
wp_get_archives | $args – 参数数组 | string|void | 获取文章归档 |
wp_get_attachment_image( $attachment_id, $size, $icon, $attr ) | $attachment_id – 附件ID, $size – 尺寸, $icon – 是否使用图标, $attr – 属性 | string | 获取附件图片 |
wp_get_attachment_image_src( $attachment_id, $size, $icon ) | $attachment_id – 附件ID, $size – 尺寸, $icon – 是否使用图标 | array|false | 获取附件图片信息 |
wp_get_attachment_metadata( $attachment_id ) | $attachment_id (int) – 附件ID | array|false | 获取附件元数据 |
wp_get_attachment_url( $attachment_id ) | $attachment_id (int) – 附件ID | string|false | 获取附件URL |
wp_attachment_is_image( $attachment_id ) | $attachment_id (int) – 附件ID | bool | 检查是否为图片附件 |
the_header_image_tag() | 无 | void | 显示头部图片标签 |
get_header_image() | 无 | string|false | 获取头部图片URL |
has_header_image() | 无 | bool | 检查是否有头部图片 |
get_custom_header() | 无 | object|false | 获取自定义头部对象 |
get_background_image() | 无 | string | 获取背景图片URL |
get_background_color() | 无 | string | 获取背景颜色 |
📦 文章类型/分类法函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
get_post_type( $post ) | $post (int|WP_Post) – 文章 | string|false | 获取文章类型 |
post_type_supports( $post_type, $feature ) | $post_type – 文章类型, $feature – 功能 | bool | 检查文章类型是否支持某功能 |
get_post_types( $args, $output, $operator ) | $args – 参数, $output – 输出类型, $operator – 运算符 | array | 获取文章类型列表 |
register_post_type( $post_type, $args ) | $post_type – 文章类型名, $args – 参数 | WP_Post_Type|WP_Error | 注册文章类型 |
get_taxonomies( $args, $output, $operator ) | $args – 参数, $output – 输出类型, $operator – 运算符 | array | 获取分类法列表 |
get_taxonomy( $taxonomy ) | $taxonomy (string) – 分类法名称 | WP_Taxonomy|false | 获取分类法对象 |
register_taxonomy( $taxonomy, $object_type, $args ) | $taxonomy – 分类法名, $object_type – 对象类型, $args – 参数 | WP_Taxonomy|WP_Error | 注册分类法 |
is_object_in_taxonomy( $object_type, $taxonomy ) | $object_type – 对象类型, $taxonomy – 分类法 | bool | 检查对象类型是否在分类法中 |
wp_get_post_parent_id( $post_id ) | $post_id (int) – 文章ID | int | 获取文章父级ID |
📦 其他实用函数
| 函数 | 参数 | 返回值 | 功能 |
|---|---|---|---|
wp_parse_args( $args, $defaults ) | $args – 参数, $defaults – 默认值 | array | 解析合并参数 |
wp_remote_get( $url, $args ) | $url – 请求URL, $args – 请求参数 | array|WP_Error | 发送GET请求 |
wp_remote_post( $url, $args ) | $url – 请求URL, $args – 请求参数 | array|WP_Error | 发送POST请求 |
wp_mail( $to, $subject, $message, $headers, $attachments ) | $to – 收件人, $subject – 主题, $message – 内容, $headers – 头部, $attachments – 附件 | bool | 发送邮件 |
wp_die( $message, $title, $args ) | $message – 消息, $title – 标题, $args – 参数 | void | 终止并显示错误 |
wp_redirect( $location, $status, $x_redirect_by ) | $location – 重定向地址, $status – HTTP状态码, $x_redirect_by – 代理 | bool | 重定向 |
wp_safe_redirect( $location, $status, $x_redirect_by ) | 同上 | bool | 安全重定向 |
get_bloginfo( $show, $filter ) | $show – 显示项, $filter – 是否过滤 | string | 获取博客信息 |
bloginfo( $show ) | $show (string) – 显示项 | void | 显示博客信息 |
wp_get_theme( $stylesheet, $theme_root ) | $stylesheet – 主题样式, $theme_root – 主题根目录 | WP_Theme | 获取主题对象 |
wp_is_json_request() | 无 | bool | 检查是否为JSON请求 |
wp_rand( $min, $max ) | $min – 最小值, $max – 最大值 | int | 生成随机数 |
wp_unique_id( $prefix ) | $prefix (string) – 前缀 | string | 生成唯一ID |
wpautop( $pee, $br ) | $pee – 文本, $br – 是否保留换行 | string | 自动添加段落标签 |
absint( $maybeint ) | $maybeint (mixed) – 可能为整数的值 | int | 转换为非负整数 |
number_format_i18n( $number, $decimals ) | $number – 数字, $decimals – 小数位数 | string | 国际化数字格式化 |
date_i18n( $format, $timestamp, $gmt ) | $format – 格式, $timestamp – 时间戳, $gmt – 是否GMT | string | 国际化日期格式化 |
mysql2date( $format, $date, $translate ) | $format – 格式, $date – MySQL日期, $translate – 是否翻译 | string | 转换MySQL日期 |
wp_date( $format, $timestamp, $timezone ) | $format – 格式, $timestamp – 时间戳, $timezone – 时区 | string|false | 本地化日期格式化 |
trailingslashit( $string ) | $string (string) – 字符串 | string | 添加尾部斜杠 |
untrailingslashit( $string ) | $string (string) – 字符串 | string | 移除尾部斜杠 |
📊 总结
| 分类 | 函数数量 | 主要用途 |
|---|---|---|
| 🎨 主题相关 | 22 | 主题结构、菜单、侧边栏 |
| 📝 文章/内容 | 28 | 文章显示、内容处理 |
| 🔄 循环相关 | 8 | 文章循环控制 |
| 💬 评论相关 | 14 | 评论系统功能 |
| 👤 用户相关 | 11 | 用户认证、资料 |
| 🎯 条件标签 | 31 | 页面条件判断 |
| ⚡ 钩子/动作 | 9 | 钩子系统 |
| 🔧 选项/设置 | 8 | 数据存储 |
| 🌐 URL/路径 | 10 | 链接处理 |
| 🔒 安全/清理 | 13 | 数据安全过滤 |
| 🌍 国际化 | 13 | 多语言支持 |
| 📱 媒体/附件 | 9 | 图片、媒体处理 |
| 📦 文章类型 | 8 | CPT、分类法 |
| 📦 其他实用 | 15 | 通用功能 |