ItSolutionStuff.com

How to Add Facebook Share Button in PHP Website?

By Hardik Savani • May 14, 2024
PHP

Hi Dev,

This simple article demonstrates the php Facebook share post button. We will use the Facebook share button php. I want to share with you a custom Facebook share button php. If you have a question about creating a custom Facebook share button php, I will give a simple example with a solution.

In this post, I will show you how to make a Facebook share button in php code. we will create a simple "index.php" file and add a Facebook share button. When the user clicks on that button then it opens a Facebook page and shares your given URL. so, let's see the simple example with output:

index.php

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>How to Add Facebook Share Button in PHP - ItSolutionStuff.Com</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

</head>

<body>

<div class="container">

<h2>How to Add Facebook Share Button in PHP - ItSolutionStuff.Com</h2>

<?php

$url = "https://www.itsolutionstuff.com/post/whats-new-in-laravel-11-new-features-and-latest-updatesexample.html";

?>

<a href="javascript:window.open('https://www.facebook.com/sharer/sharer.php?u=<?php echo $url ?>', '_blank', 'width=400,height=500');void(0);" class="btn btn-primary">Share on Facebook</i></a>

</div>

</body>

</html>

Output:

I hope it can help you...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get Time Difference in Hours and Minutes in PHP?

Read Now →

How to Install PHP DOM Extension in Ubuntu 22.04?

Read Now →

How to Upgrade PHP Version from 8.2 to 8.3 in Ubuntu?

Read Now →

How to Increase memory_limit in PHP Ubuntu?

Read Now →

PHP Explode Every Character into Array Example

Read Now →

PHP Dropzone File Upload on Button Click Example

Read Now →

PHP Signature Pad Example | E-Signature Pad using Jquery Ajax and PHP

Read Now →

How to Partially Hide Email Address in PHP?

Read Now →

How to Disable Submit Button After Form Submission in PHP?

Read Now →

How to Create Zip Folder and Download in PHP?

Read Now →

PHP MySQL DataTables Server-side Processing Example

Read Now →

PHP MySQL Contact US Form with Validation Example

Read Now →

PHP CKEditor Custom File Upload Example

Read Now →