Menu Close Menu
Menu
  • Themes
  • Extensions
  • Showcase
  • Support
    • Documentation
    • Open Support Ticket
    • Terms & Conditions
  • Blog
  • Account
    • Number of items in cart: 0

      • Your cart is empty.
      • Subtotal: $0.00
      • Estimated Tax: $0.00
      • Total: $0.00
      • Checkout

Introduction to Hooks: Actions & Filters

Introduction to Hooks: Actions & Filters

Hooks in WordPress essentially allow you to manipulate code without editing core files. They are used extensively throughout WordPress and WP Club Manager and are very useful for developers.

There are two types of hook: actions and filters.

Action Hooks allow you to insert custom code at various points (wherever the hook is ran).

Filter Hooks allow you to manipulate and return a variable which it passes.

There is an excellent article on hooks and filters here.

Using hooks

If you use a hook to add or manipulate code, you can add your custom code to your theme functions.php file.

Using action hooks

To execute your own code, you hook in by using the action hook do_action( ‘action_name’ );. See below for an example on where to place your code:

add_action( 'action_name', 'your_function_name');
function your_function_name() {
	// Your code
}

Using filter hooks

Filter hooks are called throughout are code using apply_filter( ‘filter_name’, $variable );. To manipulate the passed variable, you can do something like the following:

add_filter( 'filter_name', 'your_function_name');
function your_function_name( $variable ) {
	// Your code
	
	return $variable;
}

With filters you must return a value.

To learn more about options for using hooks and filters see our Snippet docs section. Please note however, that we are unable to provide support for customisations.

4th October 2020

Post navigation

Previous

Third Party Theme Compatibility

Next

Adding A Preset Sport

Docs Categories

  • Clubs (4)
  • Getting Started (4)
  • League Tables & Rosters (3)
  • Matches (6)
  • Players & Staff (9)
  • Plugin Settings (11)
  • Shortcodes (8)
  • Snippets (4)
  • Theming & Extending (3)
  • Widgets (6)

Popular Articles

  • Third Party Theme Compatibility
  • Match List Shortcode
  • Managing Clubs
  • League Table Shortcode
  • Quick Start Guide
  • Extensions
  • Themes
  • Showcase
  • Terms
  • Documentation
  • Support
  • Support Policy
  • Blog
© 2014-20 WP Club Manager | Manage your sports club website