SHARING TO FACEBOOK – FROM DYNAMICALLY GENERATED PAGE

I have a dynamically generated page in a WordPress environment. This page uses a simple shortcode, with no parameters, but the page is launched via another page and passes a URL parameter. This parameter indicates which data set I am to display on the page. Works great, with a big but…..

The sharing on the page works. The link properly shares the location and with the URL parmeter, the correct information is displayed upon opening. BUT I want the image, description and Name to be different that the default page.

After some work, and help from others here on StackExchange, I have successfully changed the header with the facebook required meta fields and have confirmed their existence.

First the page title:

add_filter(‘document_title_parts’,’ChangeTitleParts’, 10, 1);
function ChangeTitleParts($TitleParts)
{
if ( isset( $TitleParts[ ‘title’ ] ) && $TitleParts[ ‘title’ ] == ‘Details’ )
$TitleParts[ ‘title’ ] = $_GET[ ‘Name’ ];

return $TitleParts;
}

The then changing the meta values in the header:

add_action( ‘wp_head’, ‘add_custom_meta’, 10 );
function add_custom_meta()
{
$slug = basename(get_permalink());
if( $slug == ‘details’)
{
$Name = $_GET[ ‘Name’ ];
$Desc = $_GET[ ‘Desc’ ];
$Logo = $_GET[ ‘Logo’ ];
?>
<meta property=”og:title” content=”<?php echo $Name; ?>>”/>
<meta property=”og:description” content=”<?php echo $Desc; ?>”>
<meta property=”og:image” content=”<?php echo $Logo; ?>”>
<?PHP
}
}

The facebook meta properties are as such:

<meta property=”og:title” content=”Facebook Open Graph Demo”>
<meta property=”og:image” content=”http://example.com/main-image.png”>
<meta property=”og:site_name” content=”Example Website”>
<meta property=”og:description” content=”Here is a nice description”>

The problem is, facebook refuses to display the Title, description or associated iamge, even though the required Meta values are in the header. What am I doing wrong?

Read more here:: SHARING TO FACEBOOK – FROM DYNAMICALLY GENERATED PAGE

Leave a Reply

Your email address will not be published. Required fields are marked *