In what ways can PHP be used to automate the process of selecting and displaying a specific image as a "title image" when sharing website links on platforms like Facebook?

When sharing website links on platforms like Facebook, the platform automatically selects an image to display as the "title image." To automate the process of selecting and displaying a specific image, you can use PHP to set a specific image as the Open Graph meta tag in the website's header. This meta tag specifies the image that should be used when the link is shared on social media platforms.

<?php
// Set the title image URL
$titleImage = 'https://example.com/title-image.jpg';

// Output the Open Graph meta tag for the title image
echo '<meta property="og:image" content="' . $titleImage . '">';
?>