Getting started with WordPressget_bloginfo()Enqueuing scriptsMaking network requests with HTTP APIEnqueuing Styleshome_url()Custom Post Typestemplate_includeThe Loop (main WordPress loop)AJAXThe $wpdb ObjectActions and Filterswp_get_current_user()Add/remove contact info for users with user_contactmethods filter hookCreating a custom templateCustomizer Hello WorldCustomizer Basics (Add Panel, Section, Setting, Control)The Admin Bar (aka "The Toolbar")Querying postsAlternating main loop (pre_get_posts filter)ShortcodeCreate a Post Programmaticallyget_template_part()Taxonomiesget_template_part()ShortcodesPost FormatsCustom exerpts with excerpt_length and excerpt_morePlugin developmentSecurity in WordPress - EscapingTemplate hierarchyRemove Version from Wordpress and StylesheetsChild Theme Basicsadd_action()get_template_part()Shortcode with attributeSidebarsSecurity in WordPress - SanitizationinitCreate Template for Custom Post TypeFunction: add_action()Add ShortcodeHow Can I integrate Markdown editor with Advance Custom Field's repeater Add-on.Installation and Configurationwp_get_current_user()WP-CronSecure your installationOptions APIFunction : wp_trim_words()WP_Query() LoopUpdate WordPress ManuallyThemesWP-CLIDebuggingadd_menu_page()add_submenu_page()get_option()get_permalink()get_the_category()the_title()get_the_title()add_editor_style()add_theme_support()WordPress Plugin creationRun WordPress local with XAMPPAdmin Dashboard WidgetsSite MigrationMeta BoxRemove Auto Line Breaks From Content and Excerptget_home_path()Wordpress theme and child-theme developmentREST API

add_action()

Other topics

Direct function callback

add_action( 'init', function() {
    // do something here
} );

Using a function block to hook a set of instructions. With the init hook, the set of instructions will be executed right after wordpress has finished loading the necessary components.

Function name reference callback

function my_init_function() {
    // do something here
}

add_action( 'init', 'my_init_function' );

Using the name of the function to hook a set of instructions. With the init hook, the set of instructions will be executed right after wordpress has finished loading the necessary components.

Class static method callback

class MyClass {
    static function my_init_method() {
        // do something here
    }
}

add_action( 'init', array( 'MyClass', 'my_init_method' ) );

Using a static method of a class to hook a set of instructions. With the init hook, the set of instructions will be executed right after wordpress has finished loading the necessary components.

Object method callback

class MyClass {
    function my_init_method() {
        // do something here
    }
}

$obj = new MyClass();

add_action( 'init', array( $obj, 'my_init_method' ) );

Using a method of an object to hook a set of instructions. With the init hook, the set of instructions will be executed right after wordpress has finished loading the necessary components.

Syntax:

  • add_action( $tag, $function_to_add )
  • add_action( $tag, $function_to_add, $priority )
  • add_action( $tag, $function_to_add, $priority, $accepted_args )

Parameters:

ParameterDetails
$tag(string) The name of the action to which the procedure $function_to_add will be hooked.
$function_to_add(callable) The callable function/procedure you want to be called.
$priority(int) The priority level to which the $function_to_add will be executed. Optional. Default 10.
$accepted_args(int) The number of arguments that the callable function $function_to_add accepts. Optional. Default 1.

Contributors

Topic Id: 6264

Example Ids: 21664,21665,21666,21667

This site is not affiliated with any of the contributors.