straylightagency/metadata
Composer 安装命令:
composer require straylightagency/metadata
包简介
An helper package to build metadata tags on PHP pages
README 文档
README
A helper package to build metadata tags on PHP pages.
Installation
Require this package with composer.
composer require straylightagency/metadata
Laravel without auto-discovery:
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php:
Straylightagency\Metadata\Laravel\MetadataServiceProvider::class,
Then add this line to your facades in config/app.php:
'Metadata' => Straylightagency\Metadata\Laravel\Metadata::class,
Usage
Without Laravel
Instantiate a new MetadataManager object and simply use methods provided by.
$metadata = new \Straylightagency\Metadata\MetadataManager; $metadata->title( 'Page Title' ); $metadata->description( 'Website description' ); $metadata->url( 'https://my-website-url.com/my_page/' ); $metadata->author( 'John Doe' ); $metadata->twitterCard( 'app' ); $metadata->twitterImage( asset( '/img/twitter_meta.jpg' ) ); $metadata->ogImage( asset( '/img/facebook_meta.jpg' ), width: 1200, height: 600, type: 'jpeg' ); $metadata->ogType( 'website' ); echo $metadata; // print the meta tags
With Laravel
The package provides by default a Facade for Laravel application. You can call methods directly using the Facade or use the alias instead.
use Straylightagency\Metadata\Laravel\Metadata; Metadata::title( 'Page title' );
API documentation
Examples bellow are using Laravel Facade Metadata.
Set title
Metadata::title( 'My page title', [flags: int = Metadata::ALL] ); Metadata::metaTitle( 'My page title' ); // only a simple meta title Metadata::twitterTitle( 'My page title' ); // meta title for Twitter Card Metadata::ogTitle( 'My page title' ); // meta title for OpenGraph
Set description
Metadata::description( 'My page description', [flags: int = Metadata::ALL] ); Metadata::metaDescription( 'My page description' ); // simply a meta description Metadata::twitterDescription( 'My page description' ); // meta description for Twitter Card Metadata::ogDescription( 'My page description' ); // meta description for OpenGraph
Set images
You can set many images
// Meta image for both Twitter Card and OpenGraph Metadata::image( url: 'https://my-website-url.com/metacard.jpg', [secure_url: ?string = null], [type: ?string = null], [width: ?int = null], [height: ?int = null], [alt: ?string = null], [flags: int = Metadata::ALL] ); // Twitter Card meta image Metadata::twitterImage( url: 'https://my-website-url.com/metacard.jpg', [alt: ?string = null] ); // Opengraph meta image Metadata::ogImage( url: 'https://my-website-url.com/metacard.jpg', [secure_url: ?string = null], [type: ?string = null], [width: ?int = null], [height: ?int = null], [alt: ?string = null] );
Set videos for OpenGraph
Metadata::ogVideo(
url: 'https://my-website-url.com/video.mp4',
[secure_url: ?string = null],
[type: ?string = null],
[width: ?string = null],
[height: ?string = null]
);
Set audios for OpenGraph
Metadata::ogAudio(
url: 'https://my-website-url.com/audio.mp3',
[secure_url: ?string = null],
[type: ?string = null]
);
Set url
Metadata::url( 'https://my-website-url.com/', [flags: int = Metadata::ALL] ); // meta URL for both Twitter and OpenGraph Metadata::twitterUrl( 'https://my-website-url.com/' ); // meta URL for Twitter Card Metadata::ogUrl( 'https://my-website-url.com/' ); // meta URL for OpenGraph
Set author
Metadata::author( 'John Doe' );
Set OpenGraph Type
Metadata::ogType( 'website', [options: array = []]);
Set Twitter Card Type
Metadata::twitterCard( 'summary' );
Set Twitter Site ID
Metadata::twitterSite( '@my_website_twitter_id' );
Set Twitter Creator ID
Metadata::twitterSite( '@creator_id' );
Set Facebook App ID
Metadata::fbAppId( 'facebook_id' );
Set Facebook Admins ID
Metadata::fbAdmins( 'facebook_admins' );
Set OpenGraph Site Name
Metadata::ogSiteName( 'My website name' );
Set OpenGraph Locale
Metadata::ogLocale( 'en_US' ); Metadata::ogLocaleAlternate( 'fr_FR', 'nl_BE', 'de_DE' ); // set alternates locales available for this page // or you can combine both using second parameter of ogLocale : Metadata::ogLocale( 'en_US', 'fr_FR', 'nl_BE', 'de_DE' );
Set Google Site Verification ID
Metadata::googleSiteVerification( 'google_site_verification_id_from_google_cloud_console' );
Set Google Bot and Google Bot News
Metadata::googleBot( 'notranslate' ); Metadata::googleBotNews( 'nosnippet' );
Set Robots meta
Metadata::robots( 'nofollow', 'noindex' ); Metadata::robots( [ 'nofollow', 'noindex' ] ); // works too
Disable Pinterest Rich Pin
Metadata::disablePinterestRichPin([value: bool = true]);
Set website content rating
Metadata::rating( 'adult' );
Set a simple meta value
Metadata::meta( 'name', 'some meta value' );
Set a Twitter Card value
Metadata::twitter( 'name', 'some Twitter Card value', [prefix: MetadataManager::TWITTER_PREFIX], [uniq: bool = false]);
Set an OpenGraph value
Metadata::opengraph( 'name', 'some OpenGraph value', [prefix: MetadataManager::OPENGRAPH_PREFIX], [uniq: bool = false]); // or use the alias method : Metadata::og( 'name', 'some OpenGraph value', [prefix: MetadataManager::OPENGRAPH_PREFIX], [uniq: bool = false]);
Generate the HTML tags
$html = Metadata::toHtml( [flags: bool = MetadataManager::ALL] );
Print HTML
Simply call the print method will echo the content returned by toHtml() :
Metadata::print( [flags: bool = MetadataManager::ALL] ); // or use the __toString magic method : $metadata = new \Straylightagency\Metadata\MetadataManager; $metadata->title( 'Page Title' ); echo $metadata; // print the meta title tag
Requirement
PHP 8.3 or above
See also
Credits
License
The MIT License (MIT).
straylightagency/metadata 适用场景与选型建议
straylightagency/metadata 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「metadata」 「twitter」 「facebook」 「tags」 「opengraph」 「helper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 straylightagency/metadata 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 straylightagency/metadata 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 straylightagency/metadata 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Handles basic OAuth/OAuth2 authentication along with classes for common services
Simple Twitter API wrapper
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
Yii2 Component to manage SEO data and metadata
A helper module for pdf-print, print and social share functionality based on bootstrap to custom modules.
Laravel package for the simplification and integration of many of your users most wanted login providers. Installation is a breeze. Never worry about OAuth again.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 53
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-14