Download the PHP package rasuvaeff/yii3-seo without Composer
On this page you can find all versions of the php package rasuvaeff/yii3-seo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rasuvaeff/yii3-seo
More information about rasuvaeff/yii3-seo
Files in rasuvaeff/yii3-seo
Package yii3-seo
Short Description Next.js-style typed SEO metadata for Yii3: title templates, OpenGraph, Twitter cards, hreflang, canonical URL, robots directives and JSON-LD
License BSD-3-Clause
Homepage https://github.com/rasuvaeff/yii3-seo
Informations about the package yii3-seo
rasuvaeff/yii3-seo
Next.js-style typed SEO metadata for Yii3. Describe a page with one declarative
Metadata object — title templates, OpenGraph, Twitter cards, hreflang,
canonical URL, robots directives, icons, verification and JSON-LD — and a
single MetadataDefaults instance supplies site-wide values. Tags land in
<head> automatically via WebViewRenderer.
Using an AI coding assistant? llms.txt has a compact API reference ready to paste into context.
Requirements
- PHP 8.3+
yiisoft/html^3.13yiisoft/yii-view-renderer^7.4
Installation
Concept
The API mirrors the Next.js Metadata API:
| Next.js | yii3-seo |
|---|---|
export const metadata = { ... } (page) |
new Metadata(...) dispatched per request |
layout metadata (defaults) |
MetadataDefaults in DI params |
title.template / default / absolute |
Title::template() / Title::absolute() |
alternates.canonical / languages |
Alternates |
openGraph / twitter |
OpenGraph + OgImage / TwitterCard |
metadataBase |
MetadataDefaults(metadataBase: ...) |
Defaults are merged with the page metadata: the title template wraps the page
title, OpenGraph/Twitter inherit unset fields, and relative URLs are resolved
against metadataBase.
Usage
1. Site-wide defaults (params)
2. Register SeoInjection in the view DI config
3. Wire the event handler
4. Dispatch SeoMetadataEvent from your action
og:title/og:description fall back to the page title/description, and
twitter:* falls back to OpenGraph — no need to repeat them.
5. Title and JSON-LD in layout
<title> and <script type="application/ld+json"> are not covered by the
injection interfaces. Inject SeoInjection into your layout and render manually:
Public API
Metadata
Immutable declarative object (all fields optional). A string title is
normalized to Title::of().
| Field | Type | Renders |
|---|---|---|
title |
string\|Title |
<title> (template applied) |
description |
string |
<meta name="description"> |
keywords |
list<string> |
<meta name="keywords"> |
authors |
list<Author> |
<meta name="author"> + <link rel="author"> |
applicationName, generator, creator, publisher |
string |
matching <meta name> |
themeColor, colorScheme |
string |
theme-color, color-scheme |
robots |
Robots |
<meta name="robots"> / googlebot |
alternates |
Alternates |
canonical + hreflang links |
openGraph |
OpenGraph |
og:* |
twitter |
TwitterCard |
twitter:* |
icons |
Icons |
<link rel="icon"> etc. |
manifest |
string |
<link rel="manifest"> |
verification |
Verification |
verification <meta> |
jsonLd |
list<JsonLd> |
<script type="application/ld+json"> |
other |
list<MetaTag> |
custom <meta> |
MetadataDefaults
Site-wide defaults: metadataBase, title (template/default),
applicationName, generator, themeColor, colorScheme, robots,
openGraph, twitter, icons, verification, jsonLd, other. Provide via
the rasuvaeff/yii3-seo → defaults parameter.
Title
| Factory | Use |
|---|---|
Title::of('Home') |
page title, template applied |
Title::absolute('Home') |
page title, template bypassed |
Title::template('%s | Acme', default: 'Acme') |
defaults: template + fallback |
Alternates
Locales match /^(?:[a-z]{2}(?:-[A-Z]{2})?|x-default)$/.
OpenGraph + OgImage
TwitterCard
Robots
| Factory / method | Directive |
|---|---|
Robots::index() |
index, follow |
Robots::noindex() / nofollow() / none() / noarchive() |
matching directives |
new Robots(['noindex', 'nosnippet']) |
custom combination |
->withNoSnippet() / ->withNoImageIndex() |
append directive |
->withMaxSnippet(-1) / ->withMaxImagePreview('large') / ->withMaxVideoPreview(30) |
Google max-* |
->withGoogleBot('noindex', ...) |
separate <meta name="googlebot"> |
Icons / Icon, Verification, Author
MetaTag
| Factory | Attribute |
|---|---|
MetaTag::name(name, content) |
name="..." |
MetaTag::property(property, content) |
property="..." |
MetaTag::httpEquiv(httpEquiv, content) |
http-equiv="..." |
JsonLd
Renders as <script type="application/ld+json"> with JSON_HEX_TAG to prevent
</script> injection.
SeoInjection
Singleton registered in DI. Implements MetaTagsInjectionInterface +
LinkTagsInjectionInterface. The package DI config also registers a service
reset hook, so stale per-request metadata is cleared between requests in
reusable runtimes.
| Method | Description |
|---|---|
setMetadata(Metadata) |
Set metadata for the current request |
clear() |
Reset (useful in tests) |
getTitle(): string |
Resolved title for <title> |
getMetaTags(): list<Meta> |
Called by WebViewRenderer |
getLinkTags(): array<Link> |
Called by WebViewRenderer |
getJsonLdHtml(): string |
Rendered JSON-LD <script> blocks |
Security
- Crawler-facing URLs (canonical, hreflang,
og:image,og:url,twitter:image) are resolved againstmetadataBase; absolute URLs are validated withFILTER_VALIDATE_URL. A relative URL with no base throwsInvalidArgumentException. - HTML escaping is handled by
Yiisoft\Html— no raw string concatenation. - JSON-LD uses
JSON_HEX_TAGto prevent</script>injection.
Examples
See examples/ for runnable scripts and a Yii3 integration sketch:
examples/yii3-app.php.
Development
License
BSD-3-Clause. See LICENSE.md.
All versions of yii3-seo with dependencies
ext-filter Version *
yiisoft/html Version ^3.13 || ^4.0
yiisoft/yii-view-renderer Version ^7.4