Skip to main content

Overview

These functions handle the core theme setup, including WordPress feature support, widget areas, script/style enqueuing, and custom post type registration.

zalbi_setup()

Sets up theme defaults and registers support for various WordPress features. This is the primary initialization function that runs on the after_setup_theme hook.

What It Does

  • Enables theme translation support
  • Adds automatic RSS feed links
  • Enables WordPress title tag management
  • Registers post thumbnail support
  • Registers navigation menus
  • Adds HTML5 support for core markup
  • Configures custom background support
  • Enables customizer selective refresh for widgets
  • Adds custom logo support

Function Signature

function zalbi_setup()

Registered Menus

Supported Features

Post Thumbnails

Featured images enabled for posts and pages

Custom Logo

Supports logos up to 250x250px with flexible dimensions

HTML5 Markup

Search forms, comments, galleries, and more use valid HTML5

Custom Background

Default white background, customizable via Theme Customizer

Usage

This function is automatically hooked and runs during theme initialization:
add_action( 'after_setup_theme', 'zalbi_setup' );
This function should not be called directly. It’s automatically executed by WordPress during theme setup.

zalbi_content_width()

Sets the global content width for embedded media based on the theme’s design.

Function Signature

function zalbi_content_width()

Parameters

None

Return Value

void
void
Sets the global $content_width variable to 640 pixels

Implementation

function zalbi_content_width() {
    $GLOBALS['content_width'] = apply_filters( 'zalbi_content_width', 640 );
}
add_action( 'after_setup_theme', 'zalbi_content_width', 0 );

Filter Hook

zalbi_content_width
int
default:"640"
Modify the default content width value
Example: Increase content width
add_filter( 'zalbi_content_width', function() {
    return 1200;
});

zalbi_widgets_init()

Registers widget areas (sidebars) for the theme.

Function Signature

function zalbi_widgets_init()

Registered Widget Areas

sidebar-1
array
Sidebar - Primary sidebar widget area

Usage

// Check if sidebar is active before displaying
if ( is_active_sidebar( 'sidebar-1' ) ) {
    dynamic_sidebar( 'sidebar-1' );
}
To add more widget areas, register additional sidebars in a child theme or using the widgets_init hook.

zalbi_scripts()

Enqueues all scripts and stylesheets for the theme, including external dependencies like Font Awesome and Google Fonts.

Function Signature

function zalbi_scripts()

Enqueued Assets

zalbi-style
stylesheet
Main theme stylesheet (style.css)
  • Version: _S_VERSION (1.0.0)
  • RTL Support: Enabled
zalbi-fontawesome
stylesheet
Font Awesome 6.4.0 icon library
  • Source: Cloudflare CDN
zalbi-google-fonts
stylesheet
Google Fonts - Nunito & Open Sans
  • Nunito: 400, 700, 900 weights
  • Open Sans: 400, 600 weights
zalbi-navigation
script
Mobile navigation toggle functionality
  • File: /js/navigation.js
  • Version: _S_VERSION
  • Footer: true
comment-reply
script
WordPress comment reply script (conditional)
  • Loaded when: Singular post/page with threaded comments enabled

Implementation

function zalbi_scripts() {
    wp_enqueue_style( 'zalbi-style', get_stylesheet_uri(), array(), _S_VERSION );
    wp_style_add_data( 'zalbi-style', 'rtl', 'replace' );

    wp_enqueue_script( 'zalbi-navigation', 
        get_template_directory_uri() . '/js/navigation.js', 
        array(), 
        _S_VERSION, 
        true 
    );
    
    wp_enqueue_style( 'zalbi-fontawesome', 
        'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css' 
    );
    
    wp_enqueue_style( 'zalbi-google-fonts', 
        'https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;900&family=Open+Sans:wght@400;600&display=swap' 
    );
    
    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}
add_action( 'wp_enqueue_scripts', 'zalbi_scripts' );

Customization Example

// Dequeue Font Awesome and use a local copy
add_action( 'wp_enqueue_scripts', function() {
    wp_dequeue_style( 'zalbi-fontawesome' );
    wp_enqueue_style( 'local-fontawesome', 
        get_stylesheet_directory_uri() . '/css/fontawesome.min.css' 
    );
}, 20 );

zalbi_register_hinchables()

Registers the “Hinchable” (Inflatable) custom post type for the catalog of inflatable rentals.

Function Signature

function zalbi_register_hinchables()

Post Type Details

post_type
string
default:"hinchable"
Internal post type identifier
slug
string
default:"catalogo"
URL slug for SEO and Polylang compatibility

Configuration

labels
array
  • name: “Hinchables”
  • singular_name: “Hinchable”
public
boolean
default:"true"
Publicly queryable and visible in admin
has_archive
boolean
default:"false"
Archive page disabled (uses custom page templates)
menu_icon
string
default:"dashicons-smiley"
Admin menu icon
supports
array
Supported features:
  • title - Post title
  • editor - Content editor
  • thumbnail - Featured image
  • excerpt - Short description

Usage Examples

// Query inflatables
$args = array(
    'post_type' => 'hinchable',
    'posts_per_page' => 10,
);
$inflatables = new WP_Query( $args );

// Check if viewing a hinchable
if ( is_singular( 'hinchable' ) ) {
    // Single inflatable template
}

URL Structure

https://example.com/catalogo/castillo-medieval/
After modifying this function, flush rewrite rules by visiting Settings → Permalinks in the WordPress admin.

zalbi_register_taxonomies()

Registers the “Tipo de Hinchable” (Inflatable Type) taxonomy for categorizing inflatables.

Function Signature

function zalbi_register_taxonomies()

Taxonomy Details

taxonomy
string
default:"tipo_hinchable"
Internal taxonomy identifier
object_type
string
default:"hinchable"
Associated post type
slug
string
default:"tipo"
URL slug for taxonomy archives

Configuration

register_taxonomy( 'tipo_hinchable', 'hinchable', array(
    'labels' => array( 
        'name'          => 'Tipos de Hinchable',
        'singular_name' => 'Tipo de Hinchable',
        'menu_name'     => 'Tipos de Hinchable',
    ),
    'public'            => true,  // Visible on frontend
    'hierarchical'      => true,  // Works like categories
    'show_ui'           => true,  // Shows in admin
    'show_admin_column' => true,  // Shows in post list
    'show_in_rest'      => true,  // Block editor support
    'rewrite'           => array( 'slug' => 'tipo' ),
) );

Key Features

Hierarchical

Supports parent/child relationships like categories

Block Editor

Full Gutenberg editor support

Admin Column

Shows assigned types in post list table

Public

Creates archive pages for each type

Usage Examples

// Get terms for a hinchable
$types = get_the_terms( $post_id, 'tipo_hinchable' );

if ( $types && ! is_wp_error( $types ) ) {
    foreach ( $types as $type ) {
        echo $type->name;
    }
}

// Query by type
$args = array(
    'post_type' => 'hinchable',
    'tax_query' => array(
        array(
            'taxonomy' => 'tipo_hinchable',
            'field'    => 'slug',
            'terms'    => 'castillos',
        ),
    ),
);
$query = new WP_Query( $args );

URL Examples

https://example.com/tipo/castillos/
https://example.com/tipo/toboganes/
https://example.com/tipo/hinchables-acuaticos/

zalbi_register_eventos()

Registers the “Evento” (Event) custom post type for showcasing event management services.

Function Signature

function zalbi_register_eventos()

Post Type Details

post_type
string
default:"evento"
Internal post type identifier
slug
string
default:"eventos"
URL slug for SEO purposes

Configuration

labels
array
  • name: “Eventos”
  • singular_name: “Evento”
public
boolean
default:"true"
Publicly queryable and visible in admin
has_archive
boolean
default:"false"
Archive disabled (uses custom template)
menu_icon
string
default:"dashicons-calendar-alt"
Calendar icon in admin menu
supports
array
  • title - Event name
  • editor - Event description
  • thumbnail - Featured image
  • excerpt - Short summary

Implementation

function zalbi_register_eventos() {
    $args = array(
        'labels' => array( 
            'name' => 'Eventos', 
            'singular_name' => 'Evento' 
        ),
        'public' => true,
        'has_archive' => false,
        'menu_icon' => 'dashicons-calendar-alt', 
        'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
        'rewrite' => array( 'slug' => 'eventos' ), 
    );
    register_post_type( 'evento', $args );
}
add_action( 'init', 'zalbi_register_eventos' );

Usage Examples

// Query events
$events = new WP_Query( array(
    'post_type' => 'evento',
    'posts_per_page' => 6,
    'orderby' => 'date',
    'order' => 'DESC',
) );

// Display in template
if ( $events->have_posts() ) {
    while ( $events->have_posts() ) {
        $events->the_post();
        // Display event content
    }
    wp_reset_postdata();
}
This post type is designed for showcasing completed events or event types, not for scheduling future events. Consider adding a plugin for event management features like dates and booking.

zalbi_customize_whatsapp()

Adds WhatsApp floating button configuration to the WordPress Customizer.

Function Signature

function zalbi_customize_whatsapp( $wp_customize )

Parameters

$wp_customize
WP_Customize_Manager
required
WordPress Theme Customizer manager object

Customizer Section

zalbi_whatsapp_section
section
Botón WhatsApp - Section for configuring the floating WhatsApp button

Settings & Controls

zalbi_whatsapp_number
text
WhatsApp phone number settingProperties:
  • Default: Empty string
  • Transport: refresh
  • Sanitization: sanitize_text_field
  • Label: “Número de teléfono”
  • Description: “Escribe el número con prefijo (ej: 34658887358). Si lo dejas vacío, el botón desaparece.”

Implementation

function zalbi_customize_whatsapp($wp_customize) {
    $wp_customize->add_section('zalbi_whatsapp_section', array(
        'title'       => __('Botón WhatsApp', 'zalbi'),
        'description' => __('Configura aquí el número del botón flotante.', 'zalbi'),
        'priority'    => 120,
    ));

    $wp_customize->add_setting('zalbi_whatsapp_number', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'sanitize_text_field',
    ));

    $wp_customize->add_control('zalbi_whatsapp_number', array(
        'label'       => __('Número de teléfono', 'zalbi'),
        'section'     => 'zalbi_whatsapp_section',
        'type'        => 'text',
        'description' => 'Escribe el número con prefijo (ej: 34658887358).',
    ));
}
add_action('customize_register', 'zalbi_customize_whatsapp');

Retrieving the Value

// Get the WhatsApp number
$whatsapp_number = get_theme_mod( 'zalbi_whatsapp_number' );

// Display button if number is set
if ( ! empty( $whatsapp_number ) ) {
    echo '<a href="https://wa.me/' . esc_attr( $whatsapp_number ) . '" 
             class="whatsapp-float" 
             target="_blank" 
             rel="noopener">';
    echo '<i class="fab fa-whatsapp"></i>';
    echo '</a>';
}
Phone Number Format: Use international format without + symbol (e.g., 34658887358 for Spain)

Display Logic

1

User enters phone number

Admin enters WhatsApp number in Customizer with country code
2

Template checks for value

Theme template checks if zalbi_whatsapp_number theme mod exists and is not empty
3

Button renders

If number exists, floating WhatsApp button displays on the site
4

Empty = Hidden

If field is empty, button does not display

Constants

_S_VERSION

_S_VERSION
string
default:"1.0.0"
Theme version constant used for cache busting assets
Definition:
if ( ! defined( '_S_VERSION' ) ) {
    define( '_S_VERSION', '1.0.0' );
}
Usage:
  • Appended to script/style URLs as version parameter
  • Forces browser cache refresh when theme is updated
  • Should be incremented with each theme release

Hooks Reference

  • after_setup_theme - Runs zalbi_setup() and zalbi_content_width()
  • widgets_init - Runs zalbi_widgets_init()
  • wp_enqueue_scripts - Runs zalbi_scripts()
  • init - Runs zalbi_register_hinchables(), zalbi_register_taxonomies(), zalbi_register_eventos()
  • customize_register - Runs zalbi_customize_whatsapp()
  • zalbi_content_width - Modify default content width (default: 640)
  • zalbi_custom_background_args - Customize background feature arguments

Next Steps

Learn about template tag functions for displaying post metadata and content

Build docs developers (and LLMs) love