Skip to content

WordPress Hooks

This guide explains WordPress hooks, filters, and actions used in LamaPress.

Table of Contents


Overview

LamaPress uses WordPress hooks (actions and filters) to integrate with WordPress core and extend functionality. Hooks are organized by purpose and priority.

Actions

Theme Setup

after_setup_theme

  • Registers theme support
  • Adds image sizes
  • Sets up menus

Example:

php
add_action('after_setup_theme', 'llAddCustomImageSizes');

Initialization

init

  • Registers post types
  • Registers taxonomies
  • Removes default image sizes

Example:

php
add_action('init', 'llRemoveDefaultImageSizes');

Enqueuing Assets

wp_enqueue_scripts

  • Enqueues JavaScript
  • Enqueues CSS
  • Adds Vite integration

Example:

php
add_action('wp_enqueue_scripts', 'llEnqueueAssets');

Filters

Template Filters

theme_{post_type}_templates

  • Adds custom templates for post types

Example:

php
add_filter('theme_page_templates', 'llAddTemplates', 10, 4);

Content Filters

wp_handle_upload_prefilter

  • Validates file uploads
  • Checks file size limits

Example:

php
add_filter('wp_handle_upload_prefilter', 'llCustomFileSizeLimit');

Image Filters

big_image_size_threshold

  • Sets custom image size threshold

Example:

php
add_filter('big_image_size_threshold', 'llBigImageSizeTreshold', 999, 1);

acf/validate_attachment/type=image

  • Validates ACF image fields

Example:

php
add_filter('acf/validate_attachment/type=image', 'llValidateImageField', 10, 5);

Custom Hooks

LamaPress provides custom hooks for extending functionality:

ll_before_section

  • Fires before section renders

ll_after_section

  • Fires after section renders

Example:

php
add_action('ll_before_section', function($section_name, $key) {
    // Custom logic
}, 10, 2);

Best Practices

1. Use Appropriate Priority

Set priority based on when hook should run:

php
// Early priority
add_action('init', 'myFunction', 1);

// Default priority
add_action('init', 'myFunction', 10);

// Late priority
add_action('init', 'myFunction', 999);

2. Check Function Existence

Check if functions exist before using:

php
if (function_exists('acf_add_local_field_group')) {
    // Use ACF function
}

3. Document Hooks

Document custom hooks:

php
/**
 * Fires before section renders
 *
 * @param string $section_name Section name
 * @param string $key Section key
 */
do_action('ll_before_section', $section_name, $key);

Next Steps:

Released under the MIT License.