1. Go to this page and download the library: Download artisanpack-ui/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/ */
artisanpack-ui / seo example snippets
// Add the HasSeo trait to your model
use ArtisanPackUI\Seo\Traits\HasSeo;
class Post extends Model
{
use HasSeo;
}
use ArtisanPackUI\Ai\Contracts\FeatureRegistry;
app( FeatureRegistry::class )->disable( 'seo.analyze_content' );
use ArtisanPackUI\Seo\Events\SeoMetaCreated;
use ArtisanPackUI\Seo\Events\SeoMetaUpdated;
use ArtisanPackUI\Seo\Events\SitemapGenerated;
use ArtisanPackUI\Seo\Events\RedirectHit;
// Listen for SEO meta changes
Event::listen(SeoMetaUpdated::class, function ($event) {
// $event->seoMeta contains the updated meta
// $event->model contains the associated model
});
// Listen for redirect hits
Event::listen(RedirectHit::class, function ($event) {
// $event->redirect contains the redirect record
// $event->request contains the HTTP request
});
// Get the SEO service
$seo = seo();
// Get SEO meta for a model
$meta = seoMeta($post);
// Format a page title with site name
$title = seoTitle('My Page'); // "My Page | Site Name"
// Truncate description to SEO length
$desc = seoDescription($longText); // Truncated to 160 chars
// Check if a feature is enabled
if (seoIsEnabled('sitemap')) {
// Generate sitemap
}
// Get configuration value
$separator = seoConfig('site.separator');
use ArtisanPackUI\Seo\Contracts\SchemaBuilderInterface;
class CustomSchemaBuilder implements SchemaBuilderInterface
{
public function build($model, array $data = []): array
{
return [
'@context' => 'https://schema.org',
'@type' => 'CustomType',
// ... custom properties
];
}
}
// Register via service provider
$this->app->bind('seo.schema.custom', CustomSchemaBuilder::class);
use ArtisanPackUI\Seo\Contracts\AnalyzerInterface;
class CustomAnalyzer implements AnalyzerInterface
{
public function analyze($model): array
{
return [
'score' => 85,
'status' => 'good',
'message' => 'Content passes custom analysis.',
'suggestions' => [],
];
}
}
use function addFilter;
// Modify meta tags before the DTO is built
addFilter( 'ap.seo.metaTags', function ( array $tags, ?Model $subject, Request $request ): array {
$tags['additionalMeta']['x-custom'] = 'Custom value';
return $tags;
} );
// Add or remove sitemap entries per sitemap type
addFilter( 'ap.seo.sitemapEntries', function ( array $entries, string $sitemapType ): array {
if ( 'page' === $sitemapType ) {
$entries[] = [
'url' => 'https://example.com/extra',
'lastmod' => now()->toIso8601String(),
'changefreq' => 'weekly',
'priority' => 0.6,
];
}
return $entries;
} );