add_filter and apply_filters calls used throughout the theme.
Custom Background Filters
zalbi_custom_background_args
Filters custom background arguments
Applied filter (can be hooked into)
Array of custom background arguments
functions.php:66default-color:'ffffff'(white)default-image:''(empty)
functions.php
Changes to this filter affect the default background settings in the WordPress Customizer under “Appearance > Background”.
Content Width Filters
zalbi_content_width
Filters the content width in pixels
Applied filter (can be hooked into)
Content width in pixels (default: 640)
functions.php:96$content_width variable, which affects embedded content like videos, images, and oEmbeds. WordPress uses this value to determine the maximum width of embedded media.
Default Value: 640 pixels
Source Code:
functions.php
Why Content Width Matters
Why Content Width Matters
The
$content_width global variable is important for several reasons:- Embedded Media: WordPress uses this value to set the maximum width for embedded videos, images, and other media from services like YouTube, Vimeo, etc.
- Image Scaling: Helps WordPress determine appropriate image sizes when generating thumbnails.
- Responsive Design: Ensures embedded content doesn’t overflow the content area on different screen sizes.
- Performance: Prevents unnecessarily large images from being loaded when smaller sizes would suffice.
Custom Header Filters
zalbi_custom_header_args
Filters custom header arguments
Applied filter (can be hooked into)
Array of custom header arguments
inc/custom-header.php:23default-image:''(empty)default-text-color:'000000'(black)width:1000pixelsheight:250pixelsflex-height:truewp-head-callback:'zalbi_header_style'
inc/custom-header.php
Custom Header Arguments Explained
Custom Header Arguments Explained
| Argument | Type | Description |
|---|---|---|
default-image | string | URL to default header image |
default-text-color | string | Hex color code (without #) for header text |
width | integer | Suggested width in pixels |
height | integer | Suggested height in pixels |
flex-width | boolean | Allow flexible width |
flex-height | boolean | Allow flexible height |
wp-head-callback | string | Callback function for custom CSS |
Body Class Filters
body_class
WordPress core filter for body classes
Adds custom body classes
Array of CSS classes for the body element
Default priority
inc/template-functions.php:27<body> element based on page context. This helps with styling and conditional CSS rules.
Classes Added:
hfeed: Added to non-singular pages (archives, blog index, etc.)no-sidebar: Added when the sidebar widget area is inactive
inc/template-functions.php
Why Use Body Classes?
Why Use Body Classes?
Body classes are extremely useful for:
-
Conditional Styling: Apply different CSS rules based on page context
-
JavaScript Targeting: Identify page types in JavaScript
-
Template Variations: Style the same template differently based on context
-
Accessibility: Provide visual feedback for different states
Filter Reference Table
Complete Filters List
Complete Filters List
| Filter | Type | Parameters | File | Purpose |
|---|---|---|---|---|
zalbi_custom_background_args | apply_filters | array | functions.php:66 | Modify custom background settings |
zalbi_content_width | apply_filters | integer | functions.php:96 | Modify content width value |
zalbi_custom_header_args | apply_filters | array | custom-header.php:23 | Modify custom header settings |
body_class | add_filter | array | template-functions.php:27 | Add custom body CSS classes |
Filter Development Best Practices
When extending the theme using filters, follow these best practices:
1. Use Appropriate Priority
2. Always Return Values
3. Check Data Types
4. Use Conditional Logic
5. Document Your Filters
Creating Custom Filters
If you’re developing a child theme or plugin that extends Zalbi, you can create your own filters:zalbi_) to avoid conflicts with other themes and plugins.