Cách thêm các thẻ meta name="og:description" FB Open Graph & Twitter Cards META cho JOOMLA

Viết bởi 

Các bài trước Lamwebseo.com có hướng dẫn các bạn cách tạo các thẻ META vào Header website cũng như tác dụng của thẻ meta tới thứ hạng và cách đánh kết quả của google

Các bạn có thể tìm đọc lại bài viết đó ở link dưới đây:

Kinh nghiệm - kiến thức SEO > Các thẻ meta quan trọng và cần cho website? Seo website bạn đã có chưa?

Kiến thức làm web > Làm web JoomLa > Kinh nghiệm SEO JOOMLA > Hướng dẫn đặt các thẻ meta vào header của website - tối ưu hóa SEO Onpage

Hôm nay Lamwebseo sẽ hướng dẫn cách add tự động để tạo các thẻ meta này cho website

Đoạn code cần như sau: thêm vào components/com_content/views/article/tmpl/default.php at line 22 (thêm trước cái thể đóng php nhé ?> tag)

 

if       (isset($images->image_intro) and !empty($images->image_intro))
      {
         $timage= htmlspecialchars(JURI::root().$images->image_intro);
      }
elseif   (isset($images->image_fulltext) and !empty($images->image_fulltext))
       {
         $timage= htmlspecialchars(JURI::root().$images->image_fulltext);
       }
else
       {
         $timage= 'http://www.example.com/default-image.jpg';
       }
$doc =& JFactory::getDocument();
$doc->addCustomTag( '
<meta name="twitter:title" content="'.$this->escape($this->item->title).'">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@TwitterUsernameOfWebsite">
<meta name="twitter:creator" content="@TwitterUsernameOfAuthor">
<meta name="twitter:url" content="'.JURI::current().'">
<meta name="twitter:description" content="'.strip_tags($this->item->introtext).'">
<meta name="twitter:image" content="'.$timage.'">
<meta property="og:title" content="'.$this->escape($this->item->title).'"/>
<meta property="og:type" content="article"/>
<meta property="og:email" content="This email address is being protected from spambots. You need JavaScript enabled to view it."/>
<meta property="og:url" content="'.JURI::current().'"/>
<meta property="og:image" content="'.$timage.'"/>
<meta property="og:site_name" content="Your Website Name Here"/>
<meta property="fb:admins" content="johndoe.3"/>
<meta property="og:description" content="'.strip_tags($this->item->introtext).'"/>
');

 

Chúc bạn thành công



Sln đc: 7902 lần
Sửa lần cuối vào Thứ ba, 28 Tháng 6 2016 11:41