Download the PHP package butschster/meta-tags without Composer
On this page you can find all versions of the php package butschster/meta-tags. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package meta-tags
The most powerful and extendable tools for managing SEO Meta Tags in your Laravel project
Laravel SEO Meta Tags offers a sophisticated solution for Laravel applications, allowing developers to seamlessly manage header meta tags, CSS, JavaScript, and other relevant tags. Its primary objective is to simplify the process of managing search engine optimization (SEO) tags within your application.
Moreover, its versatile API makes it compatible with frameworks like Inertiajs, VueJS and other JavaScript frameworks.
For any questions or further assistance, please join our official telegram group
Contributing
We enthusiastically invite you to contribute to the package! Whether you've uncovered a bug, have innovative feature suggestions, or wish to contribute in any other capacity, we warmly welcome your participation. Simply open an issue or submit a pull request on our GitHub repository to get started.
Remember, every great developer was once a beginner. Contributing to open source projects is a step in your journey to becoming a better developer. So, don't hesitate to jump in and start contributing!
We appreciate any contributions to help make the package better!
Supercharge Your Development with Buggregator
Pair it with our tool for a more robust development environment. For more information visit buggregator.dev
Features
- Meta Management: Effortlessly set titles, charset, pagination links, and more.
- Styles & Scripts: Organize and place styles and scripts anywhere in your HTML.
- Custom Tags: Make your own tags to suit specific needs.
- Rich Media Integration: Supports both Open Graph & Twitter Cards.
- Analytics Ready: Comes with Google Analytics and Yandex Metrika tracking code support, including a code builder for the latter.
- Site Verification: Supports webmaster tools site verifier tags.
- Package System: Group tags, styles, and scripts into named packages for easy inclusion anywhere.
- Robust Documentation: Clear instructions and guidelines for a seamless setup.
- Thoroughly Tested: Built to ensure reliability and stability.
Requirements
- Laravel version: 9.x to 10.x
- PHP version: 8.0 or higher
Installation and Configuration
-
Install the package: Use the following command to install the Meta Tags package in your awesome application.
- Register the Service Provider: After installing the package, you must register its service provider.
You can do it using the following artisan command:
This command will activate the App\Providers\MetaTagsServiceProvider
and publish the configuration
at config/meta_tags.php
. Within this configuration file, you can set default titles, keywords, descriptions, and other
meta tags which will be automatically inserted into your HTML.
- Verification: Ensure that
App\Providers\MetaTagsServiceProvider
has been added to the providers array in yourconfig/app.php
configuration file. If it hasn't, you'll need to add it manually. Remember, if your application isn't using theApp
namespace, update the provider class name accordingly.
And that's all! Your Laravel project is now equipped to handle SEO meta tags with ease.
Usage
Controller
You can use either Facade \Butschster\Head\Facades\Meta
or \Butschster\Head\Contracts\MetaTags\MetaInterface
in your
controller
View
To integrate meta tags into your HTML, simply insert {!! Meta::toHtml() !!}
wherever required.
Note You have two options to insert meta tags:
{!! Meta::toHtml() !!}
or the Blade directive@meta_tags
.
Here's an example of how you can use it in your view:
Placements
The package provides flexibility to insert meta tags beyond the header. You can define specific placements in your templates.
- To place meta tags in the footer, use:
Meta::footer()->toHtml()
- For custom placements, use:
Meta::placement('placement_name')->toHtml()
- Alternatively, the Blade directive can also be used:
@meta_tags('placement_name')
Packages
To avoid code repetition and improve code organization, you can group tags, assets, etc., into named packages. This allows for streamlined inclusion of sets of meta tags or assets where needed.
To create a new package:
- Navigate to the Service provider.
- Add your package within
\App\Providers\MetaTagsServiceProvider
.
To define packages, you can use the PackageManager::create
method:
Using Packages in Controllers
When specific packages are required within a controller, you can include them by referencing the package name:
Setting Global Packages
For packages that should be included on every page, you can define them in the config/meta_tags.php
:
And there you have it! With these steps, handling and organizing meta tags and assets becomes a breeze.
Note All methods available in the
Meta
class can also be utilized alongside these package functions.
API
Meta
\Butschster\Head\MetaTags\Meta
- This class implements
Illuminate\Contracts\Support\Htmlable
interface
Methods
Set the main part of meta title
Prepend title part to main title
Set the title separator
By default it gets from config
Set the description
Set the keywords
Set the robots
Set the content type
Set the viewport
Add webmaster tags You can add multiple tags
Set the prev href
Set the next href
Set the canonical link
Set canonical link, prev and next from paginator object
Add a hreflang link
Set the character encoding for the HTML document
Set the favicon
Add a custom link tag
Add a link to a css file
Add a link to a script file
Register a custom tag Our package has a lot of ways of extending. One of them is creating new tags. You are able to create a new class and share it with friends or with the laravel community. You can also create a new pull request if you think that your awesome tag is really useful.
Register tags from TagsCollection
Get a tag by name
Remove a tag by name
Add a meta tag
Add the CSRF-token tag
Remove all tags
Include required packages
Register a new package and register all tags from this package
Replace package with the same name When you replace package with a new one, old tags will be removed
Remove package by name
Get package by name
Using meta interfaces
A package has different interfaces which help you set meta tags from your objects
Seo tags
Meta extending
Meta object contains Macroable
trait and you can extend it!
For example
A little bit infirmation about macroable trait https://unnikked.ga/understanding-the-laravel-macroable-trait-dab051f09172
Meta tags placements
By default, tags place to head placement. You can specify your own placement and use their all available methods.
Package
A package object has the same methods as Meta object. You can use it for extending and creating custom tags sets.
\Butschster\Head\Packages\Package
- This class extend
Butschster\Head\MetaTags\Meta
class - This class implements
Illuminate\Contracts\Support\Htmlable
interface
Create a new package and register it in PackageManager
Get the name of the package
Add a link to a css file
Add a link to a script file
Available packages
OpenGraphPackage
Butschster\Head\Packages\Entities\OpenGraphPackage
You can use this package for managing OpenGraph meta tags
setType Set the type of your object, e.g., "video.movie".
setTitle Set the title of your object as it should appear within the graph, e.g., "The Rock".
setDescription Set the description
setSiteName Set the site name
setUrl Set the canonical URL of your object that will be used as its permanent ID in the graph.
setLocale Set the locale these tags are marked up in. Of the format language_TERRITORY
addAlternateLocale
addImage Add an image URL which should represent your object within the graph.
addVideo Add an image URL which should represent your object within the graph.
TwitterCardPackage
Butschster\Head\Packages\Entities\TwitterCardPackage
You can use this package for managing Twitter card meta tags
setType Set the type of the card: summary, summary_large_image, player, app
setSite Set the @username for the website used in the card footer.
setCreator Set the @username for the content creator / author.
setTitle Set the title
setDescription Set the description
setImage Set an image for cards that are of type summary
or summary_large_image
setVideo Set a video to cards that are of type player
addMeta Set a custom meta tag
PackageManager API
Package manager provide a store for your packages or presets. You can get them by name.
Create a new package
Register a new package
Get all registered packages
Get registered package by name
Dependencies
A package can have dependencies.
Helper classes
Tag
\Butschster\Head\MetaTags\Entities\Tag
Create a new tag
Set the placement
Get the placement
Set visibility condition
Title
\Butschster\Head\MetaTags\Entities\Title
This class is responsible for title generation
Set the default part of the title
Prepend a new part of title
Change default title parts separator
Specify max length (default length is 255)
Description
\Butschster\Head\MetaTags\Entities\Description
Script
\Butschster\Head\MetaTags\Entities\Script
This class is responsible for script links generation
Style
\Butschster\Head\MetaTags\Entities\Style
This class is responsible for css links generation
Favicon
\Butschster\Head\MetaTags\Entities\Favicon
This class is responsible for favicon link generation
Comment
\Butschster\Head\MetaTags\Entities\Comment
This class is a wrapper for tags, that allows to add comments to your tags
Conditional comment
\Butschster\Head\MetaTags\Entities\ConditionalComment
This class is a wrapper for tags, that allows to add conditional comments to your tags
Google Analytics
Has header placement!
Will return
Google TagManager
Has header placement!
Will return
Yandex Metrika
Has footer placement!
Will return
Change clickmap setting
Change webvisor setting
Change trackLinks setting
Change accurateTrackBounce setting
Change trackHash setting
Change eCommerce setting
Use alternate CDN
Disable noscript tag
Javascript variables
Will return
You can change namespace
Will return
Use cases
Multiple favicons
You can use your own package for that.
At first create your package in the MetaTagsServiceProvider App\Providers\MetaTagsServiceProvider
And then append this package into packages
section in config/meta_tags.php
:
And the every page you will see in the head seaction something like that:
Extending
If you want to extend Meta class you can do it in the App\Providers\MetaTagsServiceProvider
. Just
override registerMeta
method.
Using with inertiajs or vue-meta
You can easily convert Meta object to array ant the use values in your Js project
Example for inertiaJs
All versions of meta-tags with dependencies
php Version >=8.0
illuminate/config Version ^9.0|^10.0|^11.0
illuminate/support Version ^9.0|^10.0|^11.0
illuminate/contracts Version ^9.0|^10.0|^11.0
illuminate/console Version ^9.0|^10.0|^11.0