100个常用WordPress函数

The Top 100 Most Commonly Used WordPress Functions

WordPress is a powerful publishing platform which allows both users with no coding experience and developers alike to create and share content quickly and easily. What if you want to start developing themes and plugins for your WordPress website or for clients? Well, you don’t want to try and touch the WordPress Core code. Theme developers and plugin developers have access to hundreds of functions the WordPress core exposes so that they can extend and customize any WordPress installation to perform and behave exactly as they would like. In this article, we had a close look at some of the most popular WordPress themes like Astra, Bootstrap-Basic, Hestia, Kuhn, Mins, OceanWP, Primer, Stout, Twenty Seventeen, Understrap, and others. We checked to see what are the most common WordPress functions these themes use to create great WordPress Experiences. The following list of WordPress functions is what we found.


1. get_theme_mod()

Retrieve theme modification value for the current theme.


2. add_setting()

Add a customize setting.


4. apply_filters()

Call the functions added to a filter hook.


5. esc_attr()

Escaping for HTML attributes.


6. get_option()

Retrieves an option value based on an option name.


7. esc_url()

Checks and cleans a URL.


8. esc_html()

Escaping for HTML blocks.


9. _e()

In WordPress, strings in the php files are marked for translation to other languages, and localization using two functions: __() and _e().


10. absint()

Convert a value to non-negative integer.


11. get_template_part()

Loads a template part into a template.


12. is_singular()

Is the query for an existing single post of any post type (post, attachment, page, custom post types)?


13. get_post_type()

Retrieves the post type of the current post or of a given post.


14. get_the_ID()

Retrieve the ID of the current item in the WordPress Loop.


15. the_content()

Display the post content.


16. have_posts()

Whether current WordPress query has results to loop over.


17. post_class()

Display the classes for the post div.


18. get_comments_number()

Retrieves the amount of comments a post has.


19. the_ID()

Display the ID of the current item in the WordPress Loop.


20. is_single()

Is the query for an existing single post?


21. get_permalink()

Retrieves the full permalink for the current post or post ID.


22. get_the_title()

Retrieve post title.


23. admin_url()

Retrieves the URL to the admin area for the current site.


24. add_section()

Add a customize section.


25. is_home()

Determines if the query is for the blog homepage.


26. get_sidebar()

Load sidebar template.


27. get_footer()

Load footer template.


28. is_customize_preview()

Whether the site is being previewed in the Customizer.


29. wp_nav_menu()

Displays a navigation menu.


30. the_title()

Display or retrieve the current post title with optional markup.


31. current_user_can()

Whether the current user has a specific capability.


32. is_active_sidebar()

Whether a sidebar is in use.


33. wp_link_pages()

The formatted output of a list of pages.


34. get_the_time()

Retrieve the time at which the post was written.


35. get_the_date()

Retrieve the date on which the post was written.


36. the_permalink()

Displays the permalink for the current post.


37. the_post()

Iterate the post index in the loop.


38. esc_attr_e()

Display translated text that has been escaped for safe use in an attribute.


39. is_front_page()

Is the query for the front page of the site?


40. bloginfo()

Displays information about the current site.


41. comments_open()

Whether the current post is open for comments.


42. post_password_required()

Whether post requires password and correct password has been provided.


43. has_post_thumbnail()

Check if post has an image attached.


44. get_bloginfo()

Retrieves information about the current site.


45. get_post_format()

Retrieve the format slug for a post


46. dynamic_sidebar()

Display dynamic sidebar.


47. is_search()

Is the query for a search?


48. home_url()

Retrieves the URL for the current site where the front end is accessible.


49. comments_template()

Load the comment template specified in $file.


50. add_theme_support()

Registers theme support for a given feature.


51. add_query_arg()

Retrieves a modified URL query string.


52. has_nav_menu()

Determines whether a registered nav menu location has a menu assigned to it.


53. is_wp_error()

Check whether variable is a WordPress Error.


54. get_the_author_meta()

Retrieves the requested data of the author of the current post.


55. edit_post_link()

Displays the edit post link for post.


56. is_admin()

Whether the current request is for an administrative interface page.


57. the_excerpt()

Display the post excerpt.


58. wp_get_attachment_image_src()

Retrieve an image to represent an attachment.


59. _x()

Retrieve translated string with gettext context.


60. language_attributes()

Displays the language attributes for the html tag.


61. body_class()

Display the classes for the body element.


62. add_filter()

Hook a function or method to a specific filter action.


63. is_page()

Is the query for an existing single page?


64. register_sidebar()

Builds the definition for a single sidebar and returns the ID.


65. get_the_category_list()

Retrieve category list for a post in either HTML list or custom format.


66. get_the_tag_list()

Retrieve the tags for a post formatted as a string.


67. esc_attr_x()

Translate string with gettext context, and escapes it for safe use in an attribute.


68. get_setting()

Get value based on option. (Use get_option() instead.)


69. add_action()

Hooks a function on to a specific action.


70. have_comments()

Whether there are comments to loop over.


71. is_archive()

Is the query for an existing archive page?


72. wp_list_comments()

List comments.


73. wp_enqueue_style()

Enqueue a CSS stylesheet.


74. set_transient()

Set/update the value of a transient.


75. wp_enqueue_script()

Enqueue a script.


76. get_search_form()

Display search form.


77. get_post_thumbnail_id()

Retrieve post thumbnail ID.


78. get_transient()

Get the value of a transient.


79. the_post_thumbnail()

Display the post thumbnail.


80. get_search_query()

Retrieves the contents of the search WordPress query variable.


81. add_partial()


82. get_the_modified_date()

Retrieve the date on which the post was last modified.


83. get_author_posts_url()

Retrieve the URL to the author page for the user with the ID provided.


84. wp_footer()

Fire the wp_footer action.


85. wp_head()

Fire the wp_head action.


86. get_the_post_thumbnail()

Retrieve the post thumbnail.


87. comment_form()

Outputs a complete commenting form for use within a template.


88. number_format_i18n()

Convert float number to format based on the locale.


89. get_header()

Load header template.


90. the_posts_pagination()

Displays a paginated navigation to next/previous set of posts, when applicable.


91. register_nav_menus()

Registers navigation menu locations for a theme.


92. wp_die()

Kill WordPress execution and display HTML message with error message.


93. wp_reset_postdata()

After looping through a separate query, this function restores the $post global to the current post in the main query.


94. load_theme_textdomain()

Load the theme’s translated strings.


95. get_queried_object_id()

Retrieve ID of the current queried object.


96. esc_url_raw()

Performs esc_url() for database usage.


97. the_archive_title()

Display the archive title based on the queried object.


98. add_image_size()

Register a new image size.


99. get_theme_file_uri()

Retrieves the URL of a file in the theme.


100. get_stylesheet_uri()

Retrieves the URI of current theme stylesheet.


The Top 100 Most Commonly Used WordPress Functions Summary

Hopefully you found this cheat sheet of sorts for popular WordPress functions to be helpful. For each WordPress function in the list, we included a link to the official developer resources for WordPress, in addition to a link to an article from the community that explains further how the WordPress function mentioned works. Happy WordPress Coding to you!