Using Actions and Filters in the GavernWP WordPress Framework

Last Updated:
Category:
Gavern Framework

Actions Hooks and Filters Hooks

WordPress hooks are, essentially, triggers of sorts that allow users to, with short snippets of code, modify areas a WordPress theme or plugin, or add their own code to various parts of CMS. With action hooks and filters plugin or theme creator, and even relatively low programming blogger can easily and safely change almost any functionality without touching/modifying the original files the source code of WordPress. Because you leave the core files untouched, you can painlessly upgrade your blog/website with each new version of CMS. Hooks may seem a little advanced, but with a little practice, hooks are quite efficient at modifying a WP theme.

The two types of WordPress hooks are:

Actions

Action is a PHP function, which do not return any results, but is executed at specific points throughout the WordPress Core. Events during the loading of the theme when you can latch in a specific function. Developers, like we, are creating a custom Action using the Action API to add or remove code from an existing Action by specifying any existing Hook. This process is called “hooking“.

WordPress invokes actions by using the function:

do_action ('action-name', parameters… )

A list with all available hooks and actions you will find here…

Filters

Filters as the name suggests – filter the data. Filter hooks work on some WP content. They receive some data in the input parameter (always before some content will be used), they can be converted or downloaded from somewhere alternatives, and finally they have given to the output of the same or different data, but so that they can be used by a programmer in exactly the same order in which they occurred be used in the original data. Generally filters pass the content as arguments and expect the return value to be the filtered content. Allows you to modify data while it passes to the theme or to the browser screen.

WordPress invokes filters by using the function:

apply_filter (‘filters-name', parameters… )

A list of available Filters for GavernWP you can find here

Additional information can be found at codex.wordpress.org/Plugin_API

For a thorough listing of all action and filter hooks in WP see Adam Brown’s WordPress Hooks Database.

Using Actions and Filters in the GavernWP WordPress Framework 5.005 (100.00%) 3 votes

This article was first published

Villa Belluci - View our NEW theme
×

Tutorials & tips delivered regularly

Expand your purchase with regular tutorials and tips to making your site better, direct to your email.