jreviews:page_meta:{:name}
Filters the content of specific page meta tags (title, description, keywords, canonical_url, og: , twitter: , etc.). This hook fires for each meta tag type individually, allowing targeted customization based on the meta tag name. Use this when you need to modify a specific meta tag rather than applying logic to all tags.
You need to have a working knowledge of Hooks before you get started.
Fires during SetPageMeta middleware execution for every successful response. Each meta tag type triggers this hook with its specific name.
Parameters
| Name | Type | Description |
|---|---|---|
$content |
string |
The meta tag content to filter |
$name |
string |
The meta tag name being filtered (e.g., 'title', 'description', 'canonical_url') |
$routeName |
string |
The current route name (e.g., 'listing.detail', 'category.list', 'search') |
$attributes |
array |
Array containing contextual data (listing, category, pagination, etc.) |
Variations
This dynamic hook fires for each of the following variations. The {:name} placeholder in the hook name is replaced with one of these values:
For example, to target the canonical_url variation, you would use:
fwd_add_filter('jreviews:page_meta:canonical_url', function($content, $name, $routeName, $attributes)
{
// Your code here
return $content;
});
Boilerplate Code
Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.
fwd_add_filter('jreviews:page_meta:{:name}', function($content, $name, $routeName, $attributes)
{
// Your code here
return $content;
});
Examples
- Custom field driven canonicals in listing detail pages
- Only use custom meta description for featured listings
- Prepend Listing Count To Category Page Title Tag
Custom field driven canonicals in listing detail pages
This example allows using the URL value set in a custom field for the listing detail page canonical tag. This can be useful if for example you publish content that originated somewhere else, like a press release. Using the canonical references the original source, rather than creating a duplicate. The custom field used for the canonical URL needs to remain published, but can be de-activated from list and detail view so it's not visible on the page.
fwd_add_filter('jreviews:page_meta:canonical_url', function($url, $name, $routeName, $attributes) {
if ($routeName !== 'listing.detail') {
return $url;
}
$listing = $attributes['listing'] ?? null;
if (! $listing) {
return $url;
}
$custom = $listing->getFieldValue('jr_canonical') ?? null;
if (! $custom) {
return $url;
}
return $custom;
});
Only use custom meta description for featured listings
If you sell paid listings, you could include as part your paid plans having a customized meta description tag to make the listings more discoverable for SEO. This simple example shows how to approach this.
fwd_add_filter('jreviews:page_meta:description', function($value, $name, $routeName, $attributes) {
$listing = $attributes['listing'] ?? null;
// Only continue if it's a listing detail page
if (! $listing) {
return $value;
}
// Only continue if listing is in a paid category
if (empty($listing->paid)) {
return $value;
}
// Only continue if it's a featured listing
if (! $listing->featured) {
return \"Generic meta description for listing {$listing->title}\";
}
// Featured listings show the custom meta description or if empty the listing summary
return $listing->metadesc ?: substr($listing->summary, 0, 150).'...';
});
Prepend Listing Count To Category Page Title Tag
This example will prepend the total number of listings in a category page to the page title tag.
fwd_add_filter('jreviews:page_meta:title', function($title, $name, $routeName, $attributes) {
$categoryPage = $routeName == 'category.list';
$count = $attributes['pagination']['total'] ?? null;
if ($categoryPage && $count) {
$title = $count . ' ' . $title;
}
return $title;
});
Source Files
app/Http/Middleware/SetPageMeta.phpapp/Actions/AddListingDetailPageMetaTagsAction.php