Functions on WordPress
On WordPress, the functions are placed in the functions.php file, and you can change the functions in this file or put custom code in it.
The functions.php file is automatically loaded when you install and activate a WordPress theme, and we've included all the functions here.
This file acts like a WordPress plugin for your WordPress site and is automatically activated with your current theme. The functions.php file uses PHP code to add features or change default features on the site.
For example, a WordPress theme might add a bit of code to the functions.php file to add a new widget area to the footer, or add a custom welcome message to the WordPress dashboard.
Editing the functions.php file with custom code allows you to add post types, categories, short codes, and more to improve your website.
In any case, with the help of this file, you can add endless features to the website without installing a plugin.
Where is the location of the WordPress functions file?
The location of the functions.php file is in the template folder. If you want to add a piece of code to a WordPress site, adding it to the functions.php file is one option. But this is usually not the best way to do it. WordPress tries to separate design and functionality as much as possible. That's why we have themes that define design and plugins that define functionality.
It's even better if you can change your WordPress theme without changing how your site works, or change your plugins without affecting your site design.
If you decide to edit this file, please be very careful or preferably get help from an expert. In the following, we have given 3 important reasons to be careful when editing the functions.php file.
3 important reasons to be cautious when editing the functions.php file
Editing this file should be done carefully. 3 reasons for the importance of this issue are:
- Editing functions on WordPress will be lost when the theme is updated.
- If you change your WordPress theme, the edits will be lost.
- Creating coding errors in the functions file can damage the site.
Even something as simple as an extra semicolon can cause your entire site to fail. So if you need to change this file, get help from experienced people.
Coding mistakes in the functions.php file can also lead to various WordPress errors. You only need to edit a functions.php file if you have a child theme, and code snippets are only used with the active child theme. For example, you might want to add snippets for custom fonts, style sheets, or a language translation file specifically for a theme.
Introduction of all WordPress functions
WordPress files define many useful PHP functions. Some functions on WordPress, known as template tags, are specifically defined for use in WordPress themes. There are also some functions related to actions and filters (Plugin API), which are mainly used for developing plugins. The rest is used to create the core functionality of WordPress.
Many core WordPress functions are useful for plugin and theme developers. So, here we list most of the main functions, excluding the template tags.
All these functions are basic and necessary, and knowing them is essential for people who want to make changes to your WordPress codes.
Post functions
- get_adjacent_post
- get_boundary_post
- get_children
- get_extended
- get_next_post
- get_next_posts_link
- next_posts_link
- get_permalink
- the_permalink
- get_the_excerpt
- the_excerpt
- get_the_post_thumbnail
- get_post
- get_post_field
- get_post_ancestors
- get_post_mime_type
- get_post_status
- get_post_format
- set_post_format
- get_edit_post_link
- get_delete_post_link
- get_previous_post
- get_previous_posts_link
- previous_posts_link
- get_posts
- have_posts
- is_post
- is_single
- is_sticky
- get_the_ID
- the_ID
- the_post
- wp_get_recent_posts
- wp_get_single_post
- has_post_thumbnail
- has_excerpt
- has_post_format
Custom post functions
- register_post_status
Custom post type
- register_post_type
- is_post_type_archive
- post_type_archive_title
- add_post_type_support
- remove_post_type_support
- post_type_supports
- set_post_type
- post_type_exists
- get_post_type
- get_post_types
- get_post_type_archive_link
- get_post_type_object
- get_post_type_capabilities
- get_post_type_labels
- is_post_type_hierarchical
Post insertion and deletion
- wp_delete_post
- wp_insert_post
- wp_publish_post
- wp_trash_post
- wp_update_post
pages
- get_all_page_ids
- get_ancestors
- get_page
- get_page_link
- get_page_by_path
- get_page_by_title
- get_page_children
- get_page_hierarchy
- get_page_uri
- get_pages
- is_page
- page_uri_index
- wp_link_pages
- wp_list_pages
- wp_page_menu
- wp_dropdown_pages
Custom fields (postmeta)
- add_post_meta
- delete_post_meta
- get_post_custom
- get_post_custom_keys
- get_post_custom_values
- get_post_meta
- update_post_meta
- register_meta
attachments
- get_attached_file
- image_resize
- image_edit_before_change
- is_attachment
- is_local_attachment
- set_post_thumbnail
- update_attached_file
- wp_attachment_is_image
- wp_create_thumbnail
- wp_insert_attachment
- wp_delete_attachment
- wp_get_attachment_image
- wp_get_attachment_link
- wp_get_attachment_image_src
- wp_get_attachment_metadata
- wp_get_attachment_thumb_file
- wp_get_attachment_thumb_url
- wp_get_attachment_url
- wp_check_for_changed_slugs
- wp_count_posts
- wp_get_mime_types
- wp_mime_type_icon
- wp_generate_attachment_metadata
- wp_prepare_attachment_for_js
- wp_update_attachment_metadata
Bookmark
- get_bookmark
- get_bookmarks
- wp_list_bookmarks
Main items
- wp_get_post_categories
- wp_set_post_categories
- wp_get_post_tags
- wp_set_post_tags
- wp_get_post_terms
- wp_set_post_terms
- wp_count_terms
- has_term
- is_object_in_term
Other cases
- add_meta_box
- remove_meta_box
- get_the_ID
- the_ID
- get_the_author
- the_author
- get_the_author_posts
- get_the_content
- the_content
- get_the_title
- the_title
- the_title_attribute
- wp_trim_excerpt
- wp_get_post_revision
- wp_get_post_revisions
- wp_is_post_revision
- paginate_links
Categories
- cat_is_ancestor_of
- get_all_category_ids
- get_ancestors
- get_cat_ID
- get_cat_name
- get_categories
- get_category
- get_category_by_path
- get_category_by_slug
- get_the_category_by_ID
- get_the_category_list
- get_category_link
- get_category_parents
- get_the_category
- single_cat_title
- in_category
- is_category
- the_category
- wp_category_checklist
- wp_dropdown_categories
- wp_list_categories
Create category
- wp_create_category
- wp_delete_category
- wp_insert_category
tags
- get_tag
- get_tag_link
- get_tags
- get_the_tag_list
- get_the_tags
- has_tag
- is_tag
- the_tags
- single_tag_title
- tag_description
- wp_generate_tag_cloud
- wp_tag_cloud
Grouping
- get_object_taxonomies
- get_edit_term_link
- get_taxonomy
- get_taxonomies
- get_term
- get_the_term_list
- get_term_by
- the_terms
- get_the_terms
- get_term_children
- get_term_link
- get_terms
- is_taxonomy
- is_tax
- is_taxonomy_hierarchical
- is_term
- taxonomy_exists
- term_exists
- register_taxonomy
- register_taxonomy_for_object_type
- wp_get_object_terms
- wp_remove_object_terms
- wp_set_object_terms
- wp_insert_term
- wp_update_term
- wp_delete_term
- wp_terms_checklist
The role of management and others
- add_cap
- add_role
- author_can
- current_user_can
- current_user_can_for_blog
- get_role
- get_super_admins
- is_super_admin
- map_meta_cap
- remove_cap
- remove_role
- user_can
Users and authors
- auth_redirect
- count_users
- count_user_posts
- count_many_users_posts
- email_exists
- get_currentuserinfo
- get_current_user_id
- get_profile
- get_user_by
- get_userdata
- get_usernumposts
- get_users
- set_current_user
- user_pass_ok
- wp_authenticate
- username_exists
- validate_username
- wp_dropdown_users
- wp_get_current_user
- wp_set_current_user
- wp_set_password
- get_author_posts_url
- get_the_modified_author
- is_multi_author
User meta
- add_user_meta
- delete_user_meta
- get_user_meta
- update_user_meta
- get_the_author_meta
User registration and deletion
- wp_create_user
- wp_delete_user
- wp_insert_user
- wp_update_user
login / logout
- is_user_logged_in
- wp_login_form
- wp_signon
- wp_logout
- wp_loginout
- wp_logout_url
Feed function
- bloginfo_rss
- comment_author_rss
- comment_link
- comment_text_rss
- do_feed
- do_feed_atom
- do_feed_rdf
- do_feed_rss
- do_feed_rss2
- fetch_feed
- fetch_rss
- get_author_feed_link
- get_bloginfo_rss
- get_category_feed_link
- get_comment_link
- get_comment_author_rss
- get_post_comments_feed_link
- get_rss
- get_search_comments_feed_link
- get_search_feed_link
- get_the_category_rss
- get_the_title_rss
- permalink_single_rss
- post_comments_feed_link
- rss_enclosure
- the_title_rss
- the_category_rss
- the_content_rss
- the_excerpt_rss
- wp_rss
HTTP API functions
- wp_remote_get
- wp_remote_retrieve_body
- wp_get_http_headers
- wp_remote_fopen
Views, ping and tracking functions
- add_ping
- add_comment_meta
- check_comment
- comment_text
- comment_form
- comments_number
- discover_pingback_server_uri
- delete_comment_meta
- do_all_pings
- do_enclose
- do_trackbacks
- generic_ping
- get_approved_comments
- get_avatar
- get_comment
- get_comment_text
- get_comment_meta
- get_comments
- wp_list_comments
- get_enclosed
- get_lastcommentmodified
- get_pung
- get_to_ping
- have_comments
- get_comment_author
- is_trackback
- pingback
- privacy_ping_filter
- sanitize_comment_cookies
- trackback
- trackback_url
- trackback_url_list
- update_comment_meta
- weblog_ping
- wp_allow_comment
- wp_count_comments
- wp_delete_comment
- wp_filter_comment
- wp_get_comment_status
- wp_get_current_commenter
- wp_insert_comment
- wp_new_comment
- wp_set_comment_status
- wp_throttle_comment_flood
- wp_update_comment
- wp_update_comment_count
- wp_update_comment_count_now
Comments functions
- comment_class
- comment_ID
- comment_author
- comment_date
- comment_time
- get_comment_date
- get_comment_time
Pagination of comments
- paginate_comments_links
- previous_comments_link
- next_comments_link
- get_comment_pages_count
Functions of filters
- has_filter
- add_filter
- apply_filters
- apply_filters_ref_array
- current_filter
- merge_filters
- remove_filter
- remove_all_filters
Functions of actions
- has_action
- add_action
- do_action
- do_action_ref_array
- did_action
- remove_action
- remove_all_actions
Functions of plugins
- plugin_basename
- plugins_url
- get_plugin_data
- get_admin_page_title
- plugin_dir_path
- register_activation_hook
- register_deactivation_hook
- menu_page_url
- is_plugin_active
- is_plugin_active_for_network
- is_plugin_inactive
- is_plugin_page
- add_contextual_help
- get_plugins
Widgets
- is_active_widget
- register_widget
- the_widget
- unregister_widget
- wp_add_dashboard_widget
- wp_convert_widget_settings
- wp_get_sidebars_widgets
- wp_get_widget_defaults
- wp_register_sidebar_widget
- wp_register_widget_control
- wp_set_sidebars_widgets
- wp_unregister_sidebar_widget
- wp_unregister_widget_control
- wp_widget_description
Settings
- register_setting
- unregister_setting
- settings_fields
- do_settings_fields
- do_settings_sections
- add_settings_field
- add_settings_section
- add_settings_error
- get_settings_errors
- settings_errors
Shortcodes
- add_shortcode
- do_shortcode
- do_shortcode_tag
- get_shortcode_regex
- remove_shortcode
- remove_all_shortcodes
- shortcode_atts
- shortcode_parse_atts
- strip_shortcodes
Format related functions
- comments_template
- get_footer
- get_header
- get_sidebar
- get_search_form
Other functions
- add_custom_background
- add_custom_image_header
- add_image_size
- add_theme_support
- body_class
- current_theme_supports
- dynamic_sidebar
- get_404_template
- get_archive_template
- get_attachment_template
- get_author_template
- get_body_class
- get_category_template
- get_comments_popup_template
- get_current_theme
- get_date_template
- get_header_image
- get_header_textcolor
- get_home_template
- get_locale_stylesheet_uri
- get_page_template
- get_paged_template
- get_post_class
- get_query_template
- get_search_template
- get_single_template
- get_stylesheet
- get_stylesheet_directory
- get_stylesheet_directory_uri
- get_stylesheet_uri
- get_tag_template
- get_taxonomy_template
- get_template
- get_template_directory
- get_template_directory_uri
- get_theme_file_uri
- get_theme_file_path
- get_template_part
- get_theme
- wp_get_themes
- get_theme_data
- get_theme_support
- get_theme_mod
- get_theme_mods
- get_theme_root
- get_theme_roots
- get_theme_root_uri
- get_themes
- has_header_image
- header_image
- header_textcolor
- in_the_loop
- is_child_theme
- is_active_sidebar
- is_admin_bar_showing
- is_customize_preview
- is_dynamic_sidebar
- language_attributes
- load_template
- locale_stylesheet
- locate_template
- post_class
- preview_theme
- preview_theme_ob_filter
- preview_theme_ob_filter_callback
- register_nav_menu
- register_nav_menus
- get_registered_nav_menus
- wp_create_nav_menu
- register_sidebar
- register_sidebars
- register_theme_directory
- remove_theme_mod
- remove_theme_mods
- remove_theme_support
- require_if_theme_supports
- search_theme_directories
- set_theme_mod
- switch_theme
- validate_current_theme
- unregister_nav_menu
- unregister_sidebar
- wp_add_inline_style
- wp_clean_themes_cache
- wp_get_archives
- wp_get_nav_menu_items
- wp_get_theme
- wp_nav_menu
- wp_oembed_remove_provider
- wp_page_menu
- wp_title
Formatting functions
- absint
- add_magic_quotes
- addslashes_gpc
- antispambot
- attribute_escape
- backslashit
- balanceTags
- clean_pre
- clean_url
- convert_chars
- convert_smilies
- ent2ncr
- esc_attr
- esc_html
- esc_js
- esc_textarea
- esc_sql
- esc_url
- esc_url_raw
- force_balance_tags
- format_to_edit
- format_to_post
- funky_javascript_fix
- htmlentities2
- is_email
- js_escape
- make_clickable
- popuplinks
- remove_accents
- sanitize_email
- sanitize_file_name
- sanitize_html_class
- sanitize_key
- sanitize_mime_type
- sanitize_option
- sanitize_sql_orderby
- sanitize_text_field
- sanitize_title
- sanitize_title_for_query
- sanitize_title_with_dashes
- sanitize_user
- seems_utf8
- stripslashes_deep
- trailingslashit
- untrailingslashit
- urlencode_deep
- url_shorten
- utf8_uri_encode
- wpautop
- wptexturize
- wp_filter_kses
- wp_filter_post_kses
- wp_filter_nohtml_kses
- wp_iso_descrambler
- wp_kses
- wp_kses_array_lc
- wp_kses_attr
- wp_kses_bad_protocol
- wp_kses_bad_protocol_once
- wp_kses_bad_protocol_once2
- wp_kses_check_attr_val
- wp_kses_decode_entities
- wp_kses_hair
- wp_kses_hook
- wp_kses_html_error
- wp_kses_js_entities
- wp_kses_no_null
- wp_kses_normalize_entities
- wp_kses_normalize_entities2
- wp_kses_post
- wp_kses_split
- wp_kses_split2
- wp_kses_stripslashes
- wp_kses_version
- wp_make_link_relative
- wp_normalize_path
- wp_rel_nofollow
- wp_richedit_pre
- wp_specialchars
- wp_trim_words
- zeroise
The importance of functions on WordPress
All WordPress themes come with a powerful functions.php file. This file acts as a plugin and allows you to do many things on your WordPress site. Changes that can create a huge transformation in your site.
Changing these codes requires sufficient knowledge of PHP. If you don't have experience working with them, we suggest you get help from experienced people.
We hope this article from KeyUpSeo blog was useful for you in getting to know the functions of WordPress.
Release date : 13 June, 2024