wordpress二次开发中常用的函数大全
wordpress 2025-07-26 23
以下是 WordPress 二次开发中常用的函数大全,按功能分类整理如下:
主题相关函数
模板标签:get_header()、get_footer()、get_sidebar()、the_title()、the_content()、the_excerpt()、the_permalink()、the_post_thumbnail()、the_time()、the_category()、the_tags()、comments_template() 。
循环相关:have_posts()、the_post()、wp_reset_postdata()、WP_Query(推荐替代 query_posts()) 。
插件开发常用函数
钩子函数:add_action()、add_filter()、do_action()、apply_filters() 。
选项/设置:get_option()、update_option()、add_option()、delete_option() 。
媒体处理函数
wp_get_attachment_url()、wp_get_attachment_image()、media_handle_upload()、wp_insert_attachment()、set_post_thumbnail() 。
安全相关函数
wp_nonce_field()、wp_verify_nonce()、esc_html()、esc_attr()、esc_url()、sanitize_text_field()、wp_kses() 。
其他实用函数
home_url()、site_url()、admin_url()、wp_redirect()、is_admin()、is_front_page()、is_single()、is_page()、is_category()、is_tag()、wp_enqueue_script()、wp_enqueue_style() 。
条件标签
is_single()、is_page()、is_category()、is_tag()、is_archive()、is_search()、is_404()、comments_open() 等 。
其他模板文件
index.php(默认首页)、single.php(单篇文章)、page.php(单独页面)、archive.php(归档页)、category.php(特定分类)、tag.php(特定标签)、author.php(特定作者)、search.php(搜索结果)、404.php(404 错误页)等 。
以上函数和模板文件是WordPress二次开发的基础,熟练掌握可提升开发效率,建议结合 WordPress 官方文档和教程进一步学习 。