Laravel - 社交媒体分享带有自定义内容的按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28188352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:46:48  来源:igfitidea点击:

Laravel - social media share buttons with custom content

facebooklaravelgoogle-plusshare-button

提问by omarsafwany

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:

当我在 facebook 或 google plus 上共享页面时,如何自定义内容显示。标题、描述、图片等。. 当我现在在 facebook 上分享我的页面时,它会添加一个特定的图像和其他所需的标题。在 google plus 的情况下,图像已正确共享,但标题仍然不是我需要的。这是我目前使用它们的方式:

<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.

任何想法如何根据我的需要定制它,或者是否有任何可以支持我的软件包。另外,我是否需要在 facebook 或 google plus 上创建一个应用程序才能这样做。我只是使用分享按钮。

回答by morgan9999

something like this for facebook share

像这样的 facebook 分享

<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

首先使用https://developers.facebook.com/tools/debug/在 facebook 上调试您的页面 以清除您网站上的 facebook 缓存

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.

你不必在 facebook 上创建应用程序来使用共享按钮,我认为它与 gplus 相同,但我不确定。

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>

回答by Manny Isles

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

假设这是您的 master.blade.php 模板的内容

<!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

那么这是你的 show.blade.ph 模板,它扩展了 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')

请注意@yield('og') 和@section('og')