armancs's avatar

add meta tag dynamically for each product

In my e-commerce application when i paste a url to facebook or others social site there is no image passed with that url. i want to show the url and spceific product wise picture and title. How can i do it?

here is some code i am trying.

This is head section code :

<meta property="og:title" content="{{$code[0]->meta_keys}}">
<meta name="author" content="riroit">
<link rel="icon" type="image/png" href="{{url('/')}}/assets/images/{{$settings[0]->favicon}}" />
<title>{{$settings[0]->title}}</title>
@yield('meta_tags')

This is view section in index page where all category wise product display

@section('meta_tags')
@if($allproducts)
    @foreach($allproducts as $image)

        <meta property="og:url" content="{{url()->current()}}" />
        <meta name="keywords" content="{{$image->title}}">
        <meta property="og:image:url" content="{{$image->feature_image}}" />
        <meta property="og:image" content="{{$image->url}}" />
        <meta property="og:image:size" content="300" />
    @endforeach

@endif
@endsection
0 likes
4 replies
bobbybouwmann's avatar

So this doesn't really work that way. A page can only have one og:image object. So if you want an image on the homepage of your app you either need to pick a product or use the logo of your site.

On the single product page you can use the og:image for a specific product. That's the only way that works.

Let me know if that helps you!

1 like
Snapey's avatar

and meta tags can only appear in the <head> section of the document.

1 like
armancs's avatar

@BOBBYBOUWMANN - Thanks for your response. so, i need to add og:image in each page? but my all product is dynaic so how can i implement it i don't understand.

bobbybouwmann's avatar

You need to add this depending on the data that is showing on that page. So your code is working perfectly, except you don't have to loop over all images. You already have this data available!

Please or to participate in this conversation.