Rank is a high-performance SEO management package for the Anchor Framework. It provides a fluent, expressive API for managing metadata, Open Graph tags, and Twitter Cards, with deep, zero-config integration into the Route Context system.
- Fluent Metadata: Chainable API for setting titles, descriptions, and keywords.
- Context-Aware Titles: Automatically generates human-readable page titles based on route
entityandactioncontext. - Social Media Ready: Built-in support for Open Graph and Twitter Cards with smart fallbacks.
- Canonical Handling: Simple management of canonical URLs to prevent duplicate content issues.
- Zero-Config Integration: Automatically hooks into the
ViewEnginefor seamless template usage. - Custom Meta Tags: Ability to render any arbitrary meta name/property pair.
Rank is a package that requires installation before use.
php dock package:install Rank --packagesThis will automatically:
- Register the
RankServiceProvider. - Publish the
rank.phpconfiguration file. - Register the
rank()macro on theViewEngine. - Register the global
rank()helper.
Configuration file: App/Config/rank.php
return [
'defaults' => [
'title' => 'Anchor Framework',
'description' => 'A powerful, lightweight PHP framework.',
'image' => 'https://example.com/default-share.jpg',
'type' => 'website',
],
'og' => [
'site_name' => 'Anchor App',
],
'twitter' => [
'card' => 'summary_large_image',
'site' => '@anchorphp',
],
];Access Rank directly via the rank() helper in any view:
<!-- In your layout.php -->
<head>
<?= $this->rank()->render() ?>
</head>You can override defaults or set specific values from your controller:
// In a Controller
public function show(int $id): Response
{
$product = Product::find($id);
rank()
->setTitle($product->name)
->setDescription($product->short_description)
->setImage($product->featured_image);
return $this->asView('details', compact('product'));
}Rank leverages the framework's automatic Route Context hydration to provide relevant titles without any manual intervention.
When a request is handled, the framework automatically extracts context from the Controller and Method:
App\Account\Controllers\UserController@edit- Entity:
User - Action:
edit - Resulting Title: "Edit User"
This automation ensures that your application has sensible, SEO-friendly titles out of the box for every module.
| Method | Description |
|---|---|
setTitle(string $title) |
Sets the page title and og:title. |
setDescription(string $description) |
Sets the meta description and og:description. |
setImage(string $url) |
Sets the share image for OG and Twitter. |
setCanonical(string $url) |
Sets the canonical URL. |
setMeta(string $name, string $content) |
Sets a standard <meta name="...">. |
setOg(string $property, string $content) |
Sets an Open Graph <meta property="...">. |
render() |
Generates the HTML string of all meta tags. |
- Contextual Accuracy: Ensure your Controller names are human-friendly as they are used directly in automated titles.
- Image URLs: Always use absolute URLs for social share images (
setImage) to ensure platforms can crawl them correctly. - Macro Avoidance: While Rank uses
Macroable, avoid overwriting coreViewEnginemethods to maintain framework stability.