Hello,
I'm facing a problem with Newedge template. When the news/articles are shared by the facebook share button, the images that are shown are not the ones from the article.
You may try it yourself: https://www.ajkerprosongo.com/
//get image
$article_attribs = json_decode($this->item->attribs);
$article_images = json_decode($this->item->images);
$article_image = '';
if(isset($article_attribs->spfeatured_image) && $article_attribs->spfeatured_image != '') {
$article_image = $article_attribs->spfeatured_image;
} elseif(isset($article_images->image_fulltext) && !empty($article_images->image_fulltext)) {
$article_image = $article_images->image_fulltext;
}
//opengraph
$document = JFactory::getDocument();
$document->addCustomTag('<meta property="og:url" content="'.JURI::current().'" />');
$document->addCustomTag('<meta property="og:type" content="article" />');
$document->addCustomTag('<meta property="og:title" content="'. $this->item->title .'" />');
$document->addCustomTag('<meta property="og:description" content="'. JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) .'" />');
if ($article_image) {
$document->addCustomTag('<meta property="og:image" content="'. JURI::root().$article_image.'" />');
$document->addCustomTag('<meta property="og:image:width" content="600" />');
$document->addCustomTag('<meta property="og:image:height" content="315" />');
}
Hi,
Open the following file: /templates/shaper_newedge/html/com_content/article/default.php on 41 no line (before closing php tag) paste this code:
//get image
$article_attribs = json_decode($this->item->attribs);
$article_images = json_decode($this->item->images);
$article_image = '';
if(isset($article_attribs->spfeatured_image) && $article_attribs->spfeatured_image != '') {
$article_image = $article_attribs->spfeatured_image;
} elseif(isset($article_images->image_fulltext) && !empty($article_images->image_fulltext)) {
$article_image = $article_images->image_fulltext;
}
//opengraph
$document = JFactory::getDocument();
$document->addCustomTag('<meta property="og:url" content="'.JURI::current().'" />');
$document->addCustomTag('<meta property="og:type" content="article" />');
$document->addCustomTag('<meta property="og:title" content="'. $this->item->title .'" />');
$document->addCustomTag('<meta property="og:description" content="'. JHtml::_('string.truncate', $this->item->introtext, 155, false, false ) .'" />');
if ($article_image) {
$document->addCustomTag('<meta property="og:image" content="'. JURI::root().$article_image.'" />');
$document->addCustomTag('<meta property="og:image:width" content="600" />');
$document->addCustomTag('<meta property="og:image:height" content="315" />');
}
- Thanks
Hi,
Thanks for your reply. I have worked on following file:
> templates/shaper_newedge/sppagebuilder/addons/latest_post/site.php
> templates/shaper_newedge/html/com_content/article/default.php
- Thanks
$output .= '<div class="sppb-post-share-social">';
$output .= '<a href="#" data-type="facebook" data-url="'. $_SERVER['SERVER_NAME'] . $item->link .'" data-title="'. $item->title .'" data-media="' . $image .'" class="prettySocial fa fa-facebook"></a>';
$output .= '<a href="#" data-type="twitter" data-url="'. $_SERVER['SERVER_NAME'] . $item->link .'" data-description="'. $item->title .'" data-media="' . $image .'" data-via="joomshaper" class="prettySocial fa fa-twitter"></a>';
$output .= '<a href="#" data-type="googleplus" data-url="'. $item->link .'" data-description="'. $item->title .'" data-media="' . $image .'" class="prettySocial fa fa-google-plus"></a>';
$output .= '<a href="#" data-type="pinterest" data-url="'. $item->link .'" data-description="'. $item->title .'" data-media="' . $image .'" class="prettySocial fa fa-pinterest"></a>';
$output .= '<a href="#" data-type="linkedin" data-url="'. $item->link .'" data-title="'. $item->title .'" data-description="'. $item->title .'" data-via="joomshaper" data-media="" class="prettySocial fa fa-linkedin"></a>';
$output .= '<div class="share-icon"><i class="fa fa-share-alt"></i></div>';
$output .= '</div>';
$root = JURI::base();
$root = new JURI($root);
$root_url = $root->getScheme() . '://' . $root->getHost();
$social_url = $root_url . $item->link;
// social share
$output .= '<div class="sppb-post-share-social">';
$output .= '<a href="javascript:void(0);" class="prettySocial fa fa-facebook" onClick="window.open(\'http://www.facebook.com/sharer.php?u=' . $social_url . '\',\'Facebook\',\'width=600,height=300,left=\'+(screen.availWidth/2-300)+\',top=\'+(screen.availHeight/2-150)+\'\'); return false;" href="http://www.facebook.com/sharer.php?u=' . $social_url . '"></a>';
$output .= '<a href="javascript:void(0);" class="prettySocial fa fa-twitter" onClick="window.open(\'http://twitter.com/share?url=' . $social_url . '&text=' . str_replace(" ", "%20", $item->title) . '\',\'Twitter share\',\'width=600,height=300,left=\'+(screen.availWidth/2-300)+\',top=\'+(screen.availHeight/2-150)+\'\'); return false;" href="http://twitter.com/share?url=' . $social_url . '&text=' . str_replace(" ", "%20", $item->title) . '"></a>';
$output .= '<a href="javascript:void(0);" class="prettySocial fa fa-pinterest" onClick="window.open(\'http://www.pinterest.com/pin/create/bookmarklet/?url=' . urlencode($social_url) . '&media='. $root_url . $image . '&is_video=false&description==' . urlencode($item->introtext) . '\',\'Pinterest\',\'width=585,height=666,left=\'+(screen.availWidth/2-292)+\',top=\'+(screen.availHeight/2-333)+\'\'); return false;" href="http://www.pinterest.com/pin/create/bookmarklet/?url=' . $social_url . '"></a>';
$output .= '<a href="javascript:void(0);" class="prettySocial fa fa-linkedin" onClick="window.open(\'http://www.linkedin.com/shareArticle?mini=true&url=' . $social_url . '\',\'Linkedin\',\'width=585,height=666,left=\'+(screen.availWidth/2-292)+\',top=\'+(screen.availHeight/2-333)+\'\'); return false;" href="http://www.linkedin.com/shareArticle?mini=true&url=' . $social_url . '"></a>';
$output .= '<div class="share-icon"><i class="fa fa-share-alt"></i></div>';
$output .= '</div>'; // END:: social share