Urgent.News

What's breaking now, across thousands of outlets.

Tech

WordPress Hooks Explained: How Plugins and Themes Extend Core Without Editing It

WordPress plugins and themes change what gets displayed and how data gets processed without ever touching WordPress core's own files (the code under wp-includes / wp-admin ). What makes that possible is a mechanism called hooks , which come in two flavors: actions and filters . This blog's own theme, wpmm-blog , uses both extensively in its functions.php , so this article walks through real code…

WordPress plugins and themes extend the core functionality without altering its source code by utilizing hooks. There are two types of hooks: actions and filters. Actions allow you to run custom code at specific points in WordPress, while filters enable you to modify existing values before they are used by WordPress.

WordPress core has built-in hook points where plugins and themes can attach their own functions. These hooks work in two ways: actions and filters. Actions are used for performing side effects, like writing logs or making requests. Filters, on the other hand, are used for altering data that WordPress is about to use or display.

A filter example is changing the excerpt length on archive pages. By registering a function on the excerpt_length filter hook, you can set the excerpt length to 60 words instead of the default 55. This function receives the default value from WordPress as an argument and returns the new length.

An action example is pre-generating an Open Graph image when a post is saved or published. The save_post action is hooked using the add_action function, specifying the priority and the number of arguments the callback expects. In this case, the callback function receives three arguments: $post_ID, $post, and $update. The priority allows you to determine the order in which callbacks are executed.

Hooks provide a way for WordPress to intercept and modify its functionality without modifying the core files directly. When WordPress is updated, customizations made through hooks remain intact, as they are stored in separate files under wp-content/themes or wp-content/plugins directories. This mechanism allows for seamless collaboration between WordPress core, plugins, and themes without the risk of losing customizations during updates.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

The Test Wasn't Wrong. It Was Answering an Older Question.

The Test Wasn't Wrong. It Was Answering an Older Question. I shipped a change I had reviewed, simulated, and deployed. An hour later my acceptance suite was red.

  • Test results were misinterpreted as code errors due to outdated data
  • Three categories of red results: missing artifact, stale expectation, genuine regression
  • Genuine regression poses most insidious issue by failing test expectations

n8n-sync — Git-based version control for n8n Community Edition workflows

If you are self-hosting n8n Community Edition, you already know the pain: no built-in version control. Enterprise has Source Control at €667/mo, but for Community users, there is nothing.

  • n8n-sync offers Git-based version control for n8n Community Edition workflows
  • Features include pull, push, diff, and status commands for workflow management
  • Tool eliminates black box nature of self-hosted n8n workflows with Git integration

More from Monday 19 October →