| name | add-filter |
| description | Add a new WordPress filter hook to the Saman SEO plugin with proper documentation. Use when making functionality extensible, allowing third-party customization, or adding developer hooks. |
Add Filter Hook
Add a new filter hook to the Saman SEO plugin with proper documentation.
Arguments
$ARGUMENTS should contain: filter name (e.g., "title_separator") and description
Steps
-
Analyze where the filter should be added:
- Identify the file and function where the value is computed
- Determine what data should be filterable
- Consider what additional context to pass
-
Add the filter using saman_seo_apply_filters() so legacy aliases work:
$variable = saman_seo_apply_filters( 'saman_seo_{filter_name}', $variable, $additional_context );
- Document the filter in
FILTERS.md:
### `saman_seo_{filter_name}`
{Description of what this filter does.}
**Parameters:**
- `${variable}` ({type}) - The {description}.
- `$context` (array) - Additional context.
**Example:**
```php
add_filter( 'saman_seo_{filter_name}', function( $value, $context ) {
// Modify $value
return $value;
}, 10, 2 );
Since: {version}
## Naming Conventions
- **Prefix**: Always use `saman_seo_` prefix
- **Style**: Use snake_case for filter names
- **Clarity**: Name should describe what's being filtered
## Common Filter Patterns
### Value Filter
```php
$title = apply_filters( 'saman_seo_meta_title', $title, $post_id );
Array Filter
$schema = apply_filters( 'saman_seo_schema_data', $schema, $post, $context );
Boolean Filter
$enabled = apply_filters( 'saman_seo_feature_enabled', $enabled, $feature_name );
Output Filter
$html = apply_filters( 'saman_seo_breadcrumb_html', $html, $breadcrumbs );
Existing Filter Categories
Reference existing filters in FILTERS.md:
- Title Filters:
saman_seo_title, saman_seo_title_separator
- Meta Filters:
saman_seo_meta_description, saman_seo_canonical_url
- Schema Filters:
saman_seo_schema_*, saman_seo_jsonld_output
- Sitemap Filters:
saman_seo_sitemap_*
- Feature Toggles:
saman_seo_feature_toggle
- Admin Filters:
saman_seo_admin_*
Best Practices
- Pass sufficient context - Include related objects (post, term, etc.)
- Document the return type - Be explicit about expected return values
- Use appropriate hook priority - Default is 10, lower = earlier
- Consider backwards compatibility - Don't break existing filter signatures
- Add version since tag - Track when the filter was introduced
Example Usage
/add-filter og_image_size Customize the Open Graph image dimensions
This will:
- Find where OG images are processed
- Add the filter with proper docblock
- Update FILTERS.md with documentation