Add Meta Tags To Laravel Page
I'm trying to add description and keywords to my Laravel pages. Is this way working? Or there is something wrong? @section('title') {{trans('strings.About')}} @stop @section('descr
Solution 1:
Are you extending another template that uses all these sections
? They won't work on their own, they need to populate a placeholder in another template.
It should be something like:
<!-- layouts.master --><html><head><title>App Name - @yield('title')</title><metaname="description"content="@yield('description')"><metaname="keywords"content="@yield('keywords')"><!-- etc --></head><body>
...
</body></html>
And then your template should extend the other template.
@extends('layouts.master')
@section('title')
{{trans('strings.About')}}
@stop
@section('description', 'Share text and photos with your friends and have fun')
@section('keywords', 'sharing, sharing text, text, sharing photo, photo,')
@section('robots', 'index, follow')
@section('revisit-after', 'content="3 days')
At least, that is how I read their documentation: https://laravel.com/docs/5.2/blade
Solution 2:
You can create only one section with all these important tags that I have mentioned below. And @yield
this section in app layout <head>
section of HTML code.
@section('meta_tags')
@if($obj)
<title>{{$obj->title}} - {{env('SITE_URL', 'Site Name')}}</title><metaname='description'itemprop='description'content='{{$obj->description}}' /><?php$tags = implode(',', $obj->tags); ?><metaname='keywords'content='{{$tags}}' /><metaproperty='article:published_time'content='{{$obj->created_at}}' /><metaproperty='article:section'content='event' /><metaproperty="og:description"content="{{$obj->description}}" /><metaproperty="og:title"content="{{$obj->title}}" /><metaproperty="og:url"content="{{url()->current()}}" /><metaproperty="og:type"content="article" /><metaproperty="og:locale"content="en-us" /><metaproperty="og:locale:alternate"content="en-us" /><metaproperty="og:site_name"content="{{env('SITE_URL', 'Site Name')}}" />
@foreach($obj->images as $image)
<metaproperty="og:image"content="{{$image->url}}" />
@endforeach
<metaproperty="og:image:url"content="{{obj->image}}" /><metaproperty="og:image:size"content="300" /><metaname="twitter:card"content="summary" /><metaname="twitter:title"content="{{$obj->title}}" /><metaname="twitter:site"content="@BrnBhaskar" />
@endif
@endsection
Solution 3:
I have better one! Create Include file like this 'views/widgets/meta.blade.php'
<metaname="title"content="{{ $meta->meta_title }}"/><metaname="keywords"content="{{ $meta->meta_keywords }}"/><metaname="description"content="{{ $meta->meta_description }}"/><metaname="robots"content="index,follow"/><metaname="revisit-after"content="7 days"><metaname="coverage"content="Worldwide"><metaname="distribution"content="Global"><metaname="title"content="{{ $meta->meta_title }}"><metaname="author"content="{{ setting('site.title')}}"><metaname="url"content="{{ request()->fullUrl() }}">
@isset($metaArray->og_image)
<metaname="og_image"content="{{ asset('storage/' . $meta->og_image) }}"/><metaname="og_secureImage"content="{{ asset('storage/' . $meta->og_image) }}"/><metaname="og_imageAlt"content="{{ $meta->og_imageAlt }}"/><metaname="og_imageType"content="{{ $meta->og_imageType }}"/>
@endisset
<metaname="rating"content="General"><metaproperty=”og:title”content="{{ $meta->meta_title }}"/><metaproperty="og:description"content="{{ $meta->meta_description }}"/><metaproperty=”og:type”content=”{{ $meta->og_type }}”/>
<metaproperty="og:locale"content="en_us" /><metaproperty="og:sitename"content="{{ setting('site.title') }}" /><metaproperty="og:url"content="{{ request()->fullUrl() }}"/><metaname="twitter:card"content="summary"/><metaname="twitter:site"content="{{ setting('site.twitter_site') }}"/><metaname="twitter:creator"content="{{ setting('site.twitter_creator') }}"/>
And then whenever you want to include meta just pass array through the include
@include('widgets.meta',$meta)
And also you can replace setting() with $metaArray. I'm using Voyager.
Post a Comment for "Add Meta Tags To Laravel Page"