Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mxschll/laravel-meta-tags

Add meta tags to your Laravel project for better SEO.
https://github.com/mxschll/laravel-meta-tags

laravel laravel-application laravel-framework seo seo-meta seo-optimization

Last synced: 4 months ago
JSON representation

Add meta tags to your Laravel project for better SEO.

Awesome Lists containing this project

README

        

# Laravel Meta Tags

[![Build Status](https://travis-ci.org/mxschll/laravel-meta-tags.svg?branch=master)](https://travis-ci.org/mxschll/laravel-meta-tags)

This package allows you easily to manage HTML meta tags from your controllers, blade views or really everywhere else. It is super customizable and easy to configure.

___

## Installation

Navigate to the root directory of your Laravel project and run the following command from your console:

```
composer require mxschll/laravel-meta-tags
```

The package will automatically register a service provider.

In order to configure your installation you need to publish the configuration file:

```
php artisan vendor:publish --provider="mxschll\MetaTags\MetaTagsServiceProvider"
```

You will find the configuration file at `src/config/meta-tags.php`.

## First Step

To get started, add the `@meta` Blade directive inside the `` tag of your page:

```php+HTML

Laravel
@meta
....

```
Now all the standard tags are inserted into the page as set in the configuration file.

## Usage in Blade Templates

### Add specific meta tags

If you only want to add specific tags, you can do so by using the Blade directive `@meta_get()`:

```html

Laravel
@meta_get('keywords')
@meta_get('og:description')
....

```

### Set meta tag values

To set meta tags dynamically inside a Blade template, use `@meta_set()`:

```html

Laravel
@meta_set({
"description": "This is a very nice description.",
"robots": "noindex"
})
@meta
....

```

This generates the following meta tags:

```html
...

...
```

As you can see, the values of all description tags have changed. Of course, you can also set individual values for each tag by giving the exact tag names:

```html

Laravel
@meta_set({
"description": "This is a very nice description.",
"twitter:description": "This is a twitter card description.",
"og:description": "This is an open graph description."
"robots": "noindex"
})
@meta
....

```

This generates the following meta tags:

```html
...

...
```

## Usage in Controllers

You can set meta tags anywhere in your Laravel application by using `\Meta::set($tag, $value)`:

```php