4

How can I customize the content display when I share a page on facebook or google plus. title, description, image..etc.. When I share my page now on facebook, it adds a certain image and title other the required. In case of google plus, image is shared correctly but still the title is not the one I need. Here's how I currently use them:

<a href="http://www.facebook.com/sharer.php?u=http://www.mywebsite.com" target="_blank"></a>

<!-- Google+ -->
<a href="https://plus.google.com/share?url=http://www.mywebsite.com" target="_blank"></a>

Any idea how can I customize it to my need or if there is any packages that could support me as well. Also, do I need to create an app on facebook or google plus in order to do so. I'm just using share button.

omarsafwany
  • 3,695
  • 8
  • 44
  • 75
  • i think the title and image for facebook share is determined by meta tag of the page shared, also for gplus, but i'm not sure for gplus. – morgan9999 Jan 28 '15 at 09:53
  • Solution is very well explained here.. https://stackoverflow.com/questions/34368156/laravel-set-meta-tag-dynamically-with-section – Renny M. Roy Feb 17 '18 at 09:20

2 Answers2

2

something like this for facebook share

<meta property="og:title" content="title here" />
<meta property="og:image" content="image url here" />
<meta property="og:type" content="website" />

debug your page first on facebook using https://developers.facebook.com/tools/debug/ to clear facebook cache on your site

you don't have to create app on facebook to use share button, i think it's same with gplus but i'm not sure.

or create this page as a target url to share

<php 
    $title = 'title';
    $image = 'image';
?>
<meta property="og:title" content="{{$title}}" />
<meta property="og:image" content="{{$image}}" />
<meta property="og:type" content="website" />
<script>
    window.location = "http://www.url-to-real-shared-page";
</script>
morgan9999
  • 731
  • 1
  • 11
  • 30
  • The problem is that the head tag where all of the above should be placed is in a layout that's loaded in my view. Also the content in my view gets changed dynamically, so how can change the og data each time I want to share?! – omarsafwany Jan 28 '15 at 10:32
  • i did that too before and i couldn't find an answer. in the end what i did is create a blank page with only meta tags in it, and script to redirect to the real page. the meta content can be filled dynamically using data from url. i know this is not the best way to do it though, but it works for me. – morgan9999 Jan 28 '15 at 10:41
  • can you elaborate more please?! – omarsafwany Jan 28 '15 at 10:43
  • i edit my answer, you can pass 'title' and 'image' variable from url – morgan9999 Jan 28 '15 at 10:58
  • you can have your ogs dynamic too just pass the value from controller to your view and use og:title="{{$ogtitle}}" – Khan Shahrukh Jan 28 '15 at 11:09
0

Lets say this is the content of your master.blade.php template

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
@yield('og')
<title>Manny Isles</title>

Then this is your show.blade.ph template that extends the master.blade.php

@extends('layouts.master')

@section('content')
 {{ $blog->content }}
@endsection

@section('og')
<meta property="og:title" content="{{ $blog->title }}" />
<meta property="og:image" content="{{ $blog->image_url }}" />
<meta property="og:type" content="website" />
@endsection

Just notice the @yield('og') and @section('og')