Hello,
How can we implement OG metal tags for facebook sharing, currently it does not seem to be implemented.
Thanks
OG meta tags for Facebook
-
- Senior
- Posts: 222
- Joined: Thu Oct 01, 2015 5:33 pm
Re: OG meta tags for Facebook
I think the code has to go somewhere in the includes>meta-function.php . Where do i put the og tags for the page item.php ?
function tuff_meta_title() {
$location = Rewrite::newInstance()->get_location();
$section = Rewrite::newInstance()->get_section();
$suffix = tfc_getpref('title_suff');
switch ($location) {
case ('item'):
switch ($section) {
case 'item_add': $text = tfc_getpref('publish_title'); break;
case 'item_edit': $text = __('Edit your listing'); break;
case 'send_friend': $text = __('Send to a friend') . ' - ' . osc_item_title(); break;
case 'contact': $text = __('Contact seller') . ' - ' . osc_item_title(); break;
default:
if(tfc_getpref('item_start')) { $start = osc_item_category() . ' ' . osc_item_city() . ' ' ;}
if(tfc_getpref('item_end')) { $end = ' ' . osc_item_category() . ' ' . osc_item_city() ;}
$seodetail = tfc_seo_get_row( osc_item_id() ) ;
if( $seodetail['seo_title'] ) {
$text = $start . $seodetail['seo_title'] . $end ;
} else {
$text = $start . osc_item_title() . $end ;
}
break;
}
break;
case('page'):
$text = osc_static_page_title();
break;
case('error'):
$text = __('Error');
break;
case('search'):
$region = osc_search_region();
$city = osc_search_city();
$pattern = osc_search_pattern();
$category = osc_search_category_id();
$s_page = '';
$i_page = Params::getParam('iPage');
if($i_page != '' && $i_page > 1) {
$s_page = ' - ' . __('page') . ' ' . $i_page ;
}
$b_show_all = ($region == '' && $city == '' & $pattern == '' && $category == '');
$b_category = ($category != '');
$b_pattern = ($pattern != '');
$b_city = ($city != '');
$b_region = ($region != '');
if($b_show_all) {
$text = __('Show all listings') . ' - ' . $s_page . osc_page_title();
}
$result = '';
if($b_pattern) {
$result .= $pattern . ' » ';
}
if($b_category && is_array($category) && count($category) > 0) {
$cat = Category::newInstance()->findByPrimaryKey($category[0]);
if( $cat ) {
$result .= strtolower($cat['s_name']) . ' ' ;
}
}
if($b_city && $b_region) {
$result .= __('In').' '. $city.' '.'In'.' '.$region;
} else if($b_city) {
$result .= $city . ' » ';
} else if($b_region) {
$result .= __('In').' ' .$region . ' » ';
}
$result = preg_replace('|\s?»\s$|', '', $result);
if($result == '') {
$result = __('Search results');
}
$text = '';
if( osc_get_preference('seo_title_keyword') != '' ) {
$text .= osc_get_preference('seo_title_keyword') . ' ';
}
$text .= $result . $s_page;
break;
case('login'):
switch ($section) {
case('recover'): $text = __('Recover your password');
default: $text = tfc_getpref('login_title');
}
break;
case('register'):
$text = tfc_getpref('register_title');
break;
case('user'):
switch ($section) {
case('dashboard'): $text = __('Dashboard'); break;
case('items'): $text = __('Manage my listings'); break;
case('alerts'): $text = __('Manage my alerts'); break;
case('profile'): $text = __('Update my profile'); break;
case('pub_profile'): $text = __('Public profile') . ' - ' . osc_user_name(); break;
case('change_email'): $text = __('Change my email'); break;
case('change_password'): $text = __('Change my password'); break;
case('forgot'): $text = __('Recover my password'); break;
}
break;
case('contact'):
$text = tfc_getpref('contact_title');
break;
default:
$text = tfc_getpref('homepage_title');
break;
}
if( !osc_is_home_page() ) {
$text .= ' - ' . $suffix ;
}
return ucfirst($text);
}
function tuff_meta_title() {
$location = Rewrite::newInstance()->get_location();
$section = Rewrite::newInstance()->get_section();
$suffix = tfc_getpref('title_suff');
switch ($location) {
case ('item'):
switch ($section) {
case 'item_add': $text = tfc_getpref('publish_title'); break;
case 'item_edit': $text = __('Edit your listing'); break;
case 'send_friend': $text = __('Send to a friend') . ' - ' . osc_item_title(); break;
case 'contact': $text = __('Contact seller') . ' - ' . osc_item_title(); break;
default:
if(tfc_getpref('item_start')) { $start = osc_item_category() . ' ' . osc_item_city() . ' ' ;}
if(tfc_getpref('item_end')) { $end = ' ' . osc_item_category() . ' ' . osc_item_city() ;}
$seodetail = tfc_seo_get_row( osc_item_id() ) ;
if( $seodetail['seo_title'] ) {
$text = $start . $seodetail['seo_title'] . $end ;
} else {
$text = $start . osc_item_title() . $end ;
}
break;
}
break;
case('page'):
$text = osc_static_page_title();
break;
case('error'):
$text = __('Error');
break;
case('search'):
$region = osc_search_region();
$city = osc_search_city();
$pattern = osc_search_pattern();
$category = osc_search_category_id();
$s_page = '';
$i_page = Params::getParam('iPage');
if($i_page != '' && $i_page > 1) {
$s_page = ' - ' . __('page') . ' ' . $i_page ;
}
$b_show_all = ($region == '' && $city == '' & $pattern == '' && $category == '');
$b_category = ($category != '');
$b_pattern = ($pattern != '');
$b_city = ($city != '');
$b_region = ($region != '');
if($b_show_all) {
$text = __('Show all listings') . ' - ' . $s_page . osc_page_title();
}
$result = '';
if($b_pattern) {
$result .= $pattern . ' » ';
}
if($b_category && is_array($category) && count($category) > 0) {
$cat = Category::newInstance()->findByPrimaryKey($category[0]);
if( $cat ) {
$result .= strtolower($cat['s_name']) . ' ' ;
}
}
if($b_city && $b_region) {
$result .= __('In').' '. $city.' '.'In'.' '.$region;
} else if($b_city) {
$result .= $city . ' » ';
} else if($b_region) {
$result .= __('In').' ' .$region . ' » ';
}
$result = preg_replace('|\s?»\s$|', '', $result);
if($result == '') {
$result = __('Search results');
}
$text = '';
if( osc_get_preference('seo_title_keyword') != '' ) {
$text .= osc_get_preference('seo_title_keyword') . ' ';
}
$text .= $result . $s_page;
break;
case('login'):
switch ($section) {
case('recover'): $text = __('Recover your password');
default: $text = tfc_getpref('login_title');
}
break;
case('register'):
$text = tfc_getpref('register_title');
break;
case('user'):
switch ($section) {
case('dashboard'): $text = __('Dashboard'); break;
case('items'): $text = __('Manage my listings'); break;
case('alerts'): $text = __('Manage my alerts'); break;
case('profile'): $text = __('Update my profile'); break;
case('pub_profile'): $text = __('Public profile') . ' - ' . osc_user_name(); break;
case('change_email'): $text = __('Change my email'); break;
case('change_password'): $text = __('Change my password'); break;
case('forgot'): $text = __('Recover my password'); break;
}
break;
case('contact'):
$text = tfc_getpref('contact_title');
break;
default:
$text = tfc_getpref('homepage_title');
break;
}
if( !osc_is_home_page() ) {
$text .= ' - ' . $suffix ;
}
return ucfirst($text);
}
- tuffadmin
- Site Admin
- Posts: 1236
- Joined: Tue Jan 29, 2013 7:31 pm
Re: OG meta tags for Facebook
add it to your item.php file.
No support for unnecessary PM, use forum for support queries.
Please give us good review if you bought our theme from Osclass Market
Please give us good review if you bought our theme from Osclass Market
-
- Senior
- Posts: 222
- Joined: Thu Oct 01, 2015 5:33 pm
Re: OG meta tags for Facebook
Where in the item.php should we add?tuffadmin wrote:add it to your item.php file.
It seems item.php starts with <?php osc_current_web_theme_path('header.php') ; ?> , which references all the header tags from there.
- tuffadmin
- Site Admin
- Posts: 1236
- Joined: Tue Jan 29, 2013 7:31 pm
Re: OG meta tags for Facebook
Add this to your head.php file before </head> tag.
<?php if (osc_is_ad_page()) { ?>
<meta name="author" content="<?php echo osc_item_contact_name(); ?>" />
<?php if( osc_images_enabled_at_items() ) { if( osc_count_item_resources() > 0 ) {?>
<meta property="og:image" content="<?php echo osc_resource_url(); ?>" />
<meta property="og:site_name" content="YourWebsiteName" />
<meta property="og:url" content="<?php echo osc_item_url(); ?>" />
<meta property="og:title" content="<?php echo meta_title(); ?>" />
<meta property="og:description" content="<?php echo meta_description() ; ?>" />
<?php }}}; ?>
<?php if (osc_is_ad_page()) { ?>
<meta name="author" content="<?php echo osc_item_contact_name(); ?>" />
<?php if( osc_images_enabled_at_items() ) { if( osc_count_item_resources() > 0 ) {?>
<meta property="og:image" content="<?php echo osc_resource_url(); ?>" />
<meta property="og:site_name" content="YourWebsiteName" />
<meta property="og:url" content="<?php echo osc_item_url(); ?>" />
<meta property="og:title" content="<?php echo meta_title(); ?>" />
<meta property="og:description" content="<?php echo meta_description() ; ?>" />
<?php }}}; ?>
No support for unnecessary PM, use forum for support queries.
Please give us good review if you bought our theme from Osclass Market
Please give us good review if you bought our theme from Osclass Market
-
- Senior
- Posts: 222
- Joined: Thu Oct 01, 2015 5:33 pm
Re: OG meta tags for Facebook
Thanks Navjot,
Just extending Navjot's answer -
head.php already contains <?php if (osc_is_ad_page()) { ?> so the above code can be pasted inside.
Basides that, if you need to include og tags for your "homepage", you can add the og tag inside this function -
<?php if (osc_is_home_page()) { ?>
//Your custom og tags inside here
<?php } ?>
Cheers!
Just extending Navjot's answer -
head.php already contains <?php if (osc_is_ad_page()) { ?> so the above code can be pasted inside.
Basides that, if you need to include og tags for your "homepage", you can add the og tag inside this function -
<?php if (osc_is_home_page()) { ?>
//Your custom og tags inside here
<?php } ?>
Cheers!