Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryMarketing With Software

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

A Facebook Trick

At Facebook, when you type a URL into a post or response, the Facebook bot grabs a copy of the page at the URL.

Other social media sites may do similar things. If yes, you may be able to apply the idea in this article for those sites.

When the Facebook bot grabs a copy, it scans the HTML header for specific information. If the bot doesn't find the information it is looking for, it scans the rest of the page for clues.

I'll use my Roy Forth author website for examples in this article, specifically the page at royforth.com/series-details.php

The information the bot is looking for is in specific meta header tags:

<meta property="og:image" content="https://royforth.com/pgimg/IMG_1169-cropped-text.jpg">
<meta property="og:title" content="The 'Amish Mummy & Wild Wonder' series by Roy Forth">
<meta property="og:description" content="A series of page-turning Amish novels by an author who was raised Amish.">

Facebook can use all three of those values. The image generally is published with the post or response. The title generally is published (probably has some length considerations, although I don't know what they might be). And part or all of the description generally is published.

Now, the thing is, if you change the image or either of the text values and post the web page URL again, Facebook is likely to just publish what they had published before — instead of picking up your updated data.

The Facebook trick is to trick the bots into picking up your updated data. Append a ? and any one or more valid characters (a-z, 0-9, -, _) to the end of the URL you post. That makes the URL different and tells the bots to grab the source code anew. Your latest image, title, and description are then used.

That trick can get your updated image and text values posted.

Further below, I present PHP code that changes those three meta values depending on what is appended to the URL. You'll see what I mean when you go to these URLs and view the source code.

royforth.com/series-details.php
royforth.com/series-details.php?i0
royforth.com/series-details.php?i1
royforth.com/series-details.php?i2
royforth.com/series-details.php?i3

Each of those changes the image and also the title and description for the Facebook bot. When I post about the Amish series of novels, I can use whichever URL contains the image and text that I prefer.

To ensure the bot doesn't determine that the visuals of the pages at the various URLs are all identical, the webpage itself also changes. The headline and the description within the double-rule border below the headline are updated according to the values in the meta tags. You'll see it when you visit those URLs.

Here is the PHP source code that the Roy Forth series detail page contains. Information follows.

<?php

$Image = 'https://royforth.com/pgimg/IMG_1169-cropped-text.jpg';
$Title = "The 'Amish Mummy & Wild Wonder' series by Roy Forth";
$Description = 'A series of page-turning Amish novels by an author who was raised Amish.';

if( isset($_GET['i0']) )
{
	$Image = 'https://royforth.com/pgimg/2-book_covers.jpg';
	$Title = "The 'Amish Mummy & Wild Wonder' novels by Roy Forth";
	$Description = "The first two books of an Amish mystery series. Wild Wonder: forced out of the Amish, and changed both name and gender to hide. Amish Mummy: the highly intelligent solver of issues and subtle director of resolutions.";
}

if( isset($_GET['i1']) )
{
	$Image = 'https://books.bontragerconnection.com/author-roy-forth/altLinkImages/Screenshot%202025-05-06%20at%2015-18-03%20Grievous%20Acts%20Amish%20Mummy%20&%20Wild%20Wonder.png';
	$Title = "The 'Amish Mummy & Wild Wonder' mystery-type novels by Roy Forth";
	$Description = "An Amish man slides toward insanity after his wife dies. He rapes his oldest son and imprisons him in a shack in the woods for future use, because God forbids a man to spill his seed.";
}

if( isset($_GET['i2']) )
{
	$Image = 'https://books.bontragerconnection.com/author-roy-forth/altLinkImages/WildYellowDress01.jpg';
	$Title = "The don't-miss 'Amish Mummy & Wild Wonder' novels by Roy Forth";
	$Description = 'A grievous incident compels an Amish boy to leave home and live as a woman named Wild Wonder. After an even more grievous incident, Amish Mummy encourages Wild Wonder to eliminate the potential for further incidents.';
}

if( isset($_GET['i3']) )
{
	$Image = 'https://books.bontragerconnection.com/author-roy-forth/altLinkImages/WildYellowDress02.jpg';
	$Title = "The 'Amish Mummy & Wild Wonder' authentic Amish novels by Roy Forth";
	$Description = "An underage Amish boy was compelled by a grievous act to leave his family and the Amish community. To hide so well that he would not be returned to his father, the boy lives as a woman named Wild Wonder.";
}

?>

<meta property="og:image" content="<?php echo($Image) ?>">
<meta property="og:title" content="<?php echo(str_replace('"','&quot;',$Title)) ?>">
<meta property="og:description" content="<?php echo(str_replace('"','&quot;',$Description)) ?>">

The above is in the web page source code head area of the Roy Forth web page. Because PHP code isn't available by viewing source in a browser, all you'll be able to see is the meta tags.

In the above PHP, each different URL parameter (the "?" and text appended to a URL) has its corresponding if() statement. The PHP code sees URL parameters as values in a $_GET array, which is what you see in the above source code (the parameter value is bolded).

When I want to add another image, I determine another parameter for the URL and add a corresponding if() statement.

Above the if() statements in the source code are the default image URL, title, and description values. If the URL that loads the web page has no parameters, the default information will be used,

Below the if() statements in the source code are the meta tags. You'll see how PHP code fills in the values. For the text values, PHP code replaces any double-quotation marks with &quot; character entities — because the meta values are themselves within double-quotation marks.

It is fairly easy to add another image, title, and description to the PHP code for a new URL parameter. Simply add another if() statement.

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2025 Will Bontrager Software LLC