PHP code example of intent / intent-seo
1. Go to this page and download the library: Download intent/intent-seo library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
intent / intent-seo example snippets
use Intent\Seo\SeoMiddleware;
Route::get('/blog/{slug}', $handler)->middleware(SeoMiddleware::class);
seo()->title('My Page Title')
->description('Page description here')
->canonical('https://example.com/page')
->image('https://example.com/image.jpg')
->addSchema(Schema::article()
->headline('Article Title')
->author('Author Name')
->publishDate('2026-01-04')
->build());
seo()->title('Page Title') // Set title
->description('Description') // Set meta description
->canonical('https://...') // Set canonical URL
->robots(true, true) // index, follow
->prev('/page?p=1') // Previous page (pagination)
->next('/page?p=3') // Next page (pagination)
->openGraph('type', 'article') // Open Graph meta
->twitter('site', '@handle') // Twitter Card meta
->image('/image.jpg') // Social image (OG + Twitter)
->addSchema($schema) // Add JSON-LD schema
->render(); // Output all HTML for <head>
use Intent\Seo\Sitemap\SitemapGenerator;
Route::get('/sitemap.xml', function ($req, $res) {
$sitemap = new SitemapGenerator();
$sitemap->addUrl('https://example.com/', '2026-01-04', 'daily', 1.0);
$sitemap->addUrl('https://example.com/about', null, 'monthly', 0.8);
// Add from database
$pages = DB::table('pages')->where('status', 'published')->get();
foreach ($pages as $page) {
$sitemap->addUrl(
url('/pages/' . $page['slug']),
$page['updated_at'],
'weekly',
0.7,
[['loc' => $page['image'], 'title' => $page['title']]] // Image sitemap
);
}
return $res->header('Content-Type', 'application/xml')->send($sitemap->generate());
});
use Intent\Seo\Robots;
Route::get('/robots.txt', function ($req, $res) {
$robots = Robots::default('https://example.com');
// Or customize:
// $robots = new Robots();
// $robots->allow('/')->disallow('/admin')->sitemap('https://example.com/sitemap.xml');
return $res->header('Content-Type', 'text/plain')->send($robots->generate());
});
use Intent\Seo\Schema\Schema;
// Article
$article = Schema::article()
->headline('Article Title')
->author('Author Name')
->publishDate('2026-01-04')
->image('https://example.com/image.jpg')
->publisher('Site Name', 'https://example.com/logo.png');
seo()->addSchema($article);
// Breadcrumb
$breadcrumb = Schema::breadcrumb()
->add('Home', '/')
->add('Blog', '/blog')
->add('Article', '/blog/article');
seo()->addSchema($breadcrumb);
// Organization
$org = Schema::organization()
->name('Company Name')
->url('https://example.com')
->logo('https://example.com/logo.png')
->sameAs(['https://twitter.com/...', 'https://facebook.com/...']);
// Product (E-commerce)
$product = Schema::product()
->name('Product Name')
->description('Product description')
->price(99.99, 'USD')
->availability('InStock')
->rating(4.5, 120);
return [
'mode' => 'manual', // 'ai', 'manual', 'hybrid'
'title.pattern' => '{title} | {site_name}',
'title.site_name' => env('APP_NAME'),
'title.max_length' => 60,
'description.max_length' => 160,
'ai.provider' => 'openai',
'ai.api_key' => env('SEO_AI_API_KEY'),
'ai.model' => 'gpt-4o-mini',
];
use Intent\Seo\Config\SeoConfig;
// OpenAI
$config = new SeoConfig([
'mode' => 'ai',
'ai' => ['provider' => 'openai', 'api_key' => '...', 'model' => 'gpt-4o-mini'],
]);
// Anthropic Claude
$config = new SeoConfig([
'ai' => ['provider' => 'anthropic', 'api_key' => '...', 'model' => 'claude-3-5-sonnet'],
]);
// Google Gemini
$config = new SeoConfig([
'ai' => ['provider' => 'google', 'api_key' => '...', 'model' => 'gemini-1.5-flash'],
]);
// Local Ollama
$config = new SeoConfig([
'ai' => ['provider' => 'ollama', 'api_url' => 'http://localhost:11434', 'model' => 'llama2'],
]);
bash
> composer