most commonly used wordpress functions
Here are some of the most commonly used and crucial functions across various categories that you might encounter or need while developing themes, plugins, or customizing WordPress.
Theme Development and Template Tags
get_header()
: Includes the header.php file.get_footer()
: Includes the footer.php file.get_sidebar()
: Includes the sidebar.php file.wp_head()
: Used in the<head>
section, for loading scripts, styles, meta tags, etc.wp_footer()
: Placed before the closing</body>
tag, for loading scripts.the_content()
: Displays the post/page content.the_excerpt()
: Displays the post excerpt.get_template_directory_uri()
: Retrieves the URL of the current theme directory.the_post()
: Iterates the post index in The Loop.have_posts()
,the_post()
: Used to create The Loop, checking if there are posts and then displaying them.wp_nav_menu()
: Displays a navigation menu.add_theme_support()
: Enables features like post thumbnails, HTML5 support, custom headers, etc.
Hooks: Actions and Filters
add_action()
: Hooks a function to a specific action.add_filter()
: Hooks a function to a specific filter, allowing data modification.remove_action()
,remove_filter()
: Removes functions hooked to actions/filters.apply_filters()
: Calls the functions added to a filter hook.do_action()
: Executes functions hooked on a specific action hook.
Post, Page, and Custom Post Types
get_post_meta()
: Retrieves a post meta field for the specified post.update_post_meta()
: Updates a post meta field based on post ID.wp_insert_post()
: Inserts a new post or updates an existing one.get_posts()
,WP_Query
: Retrieve posts, pages, or custom post types.
User and Authentication
wp_login_url()
,wp_logout_url()
: Returns the login/logout URL.is_user_logged_in()
: Checks if the user is logged in.get_current_user_id()
: Retrieves the current user's ID.wp_create_user()
,wp_insert_user()
: Create a new user.
Options and Settings
get_option()
: Retrieves a value from the options table.update_option()
: Updates a value in the options table.add_option()
: Adds a new option to the options table.
Enqueue Scripts and Styles
wp_enqueue_script()
: Enqueues a script.wp_enqueue_style()
: Enqueues a stylesheet.wp_register_script()
,wp_register_style()
: Registers a script/style for later use.
For a comprehensive list and detailed documentation on each function, the WordPress Codex and the Developer Resources are invaluable resources.
Published on: Mar 11, 2024, 04:02 AM