Osclass Support Forums
Osclass plugin support => Blog and News Plugin => Topic started by: Petar Petkovski on March 04, 2021, 02:30:32 PM
-
The new structured data functionality was a great addition in the new version of osclass, which is great for social sharing. However, the blog plugin does not generate the tags at all and when sharing posts to social networks it picks up the generic site name/description and image.
In oc-include/osclass/structured_data.php
Change this
<meta property="og:title" content="<?php echo osc_esc_html(osc_is_ad_page() ? osc_item_title() : osc_page_title()); ?>" />
<meta property="og:description" content="<?php echo osc_esc_html(osc_is_ad_page() ? osc_highlight(osc_item_description(), 200) : osc_page_description()); ?>" />
To this:
<meta property="og:title" content="<?php meta_title(); ?>" />
<meta property="og:description" content="<?php echo osc_esc_html(osc_is_ad_page() ? osc_highlight(osc_item_description(), 200) : meta_description()); ?>" />
To get the featured image from the blog post, see the below answer given my MB_themes.
-
@Petar Petkovski
I do not think it is ultimate solution, but should work.
$location = Rewrite::newInstance()->get_location();
$section = Rewrite::newInstance()->get_section();
$route = Params::getParam('route');
$img = '';
if ($location == 'blg' && $section == 'article' || $route == 'blg-post') {
$blog_id = Params::getParam('blogId');
$blog = ModelBLG::newInstance()->getBlogDetail($blog_id);
$img = blg_img_link($blog['s_image']);
}
$item_resource_url = ($img <> '' ? $img : $item_resource_url);
-
This solution works fine and I can see that
<meta name="twitter:image" content="<?php echo $item_resource_url; ?>" />
and
<meta property="og:image" content="<?php echo $item_resource_url; ?>" />
are correctly returning the blog featured image :)
-
@Petar Petkovski
Cool ;)
-
@Petar Petkovski
I do not think it is ultimate solution, but should work.
$location = Rewrite::newInstance()->get_location();
$section = Rewrite::newInstance()->get_section();
$route = Params::getParam('route');
$img = '';
if ($location == 'blg' && $section == 'article' || $route == 'blg-post') {
$blog_id = Params::getParam('blogId');
$blog = ModelBLG::newInstance()->getBlogDetail($blog_id);
$img = blg_img_link($blog['s_image']);
}
$item_resource_url = ($img <> '' ? $img : $item_resource_url);
@MB Themes
I am wanting the image that I uploaded to the Blog post to be the og:image on social sharing. Where are you putting the above code?
-
@Anthony Marshall
It is not possible to use image that is just in content
-
@Anthony Marshall
It is not possible to use image that is just in content
@MB Themes
No, I meant the uploaded image when you write the blog - similar to the ads image. Isn't that what you and Peter were talking about?
-
The new structured data functionality was a great addition in the new version of osclass, which is great for social sharing. However, the blog plugin does not generate the tags at all and when sharing posts to social networks it picks up the generic site name/description and image.
In oc-include/osclass/structured_data.php
Change this
<meta property="og:title" content="<?php echo osc_esc_html(osc_is_ad_page() ? osc_item_title() : osc_page_title()); ?>" />
<meta property="og:description" content="<?php echo osc_esc_html(osc_is_ad_page() ? osc_highlight(osc_item_description(), 200) : osc_page_description()); ?>" />
To this:
<meta property="og:title" content="<?php meta_title(); ?>" />
<meta property="og:description" content="<?php echo osc_esc_html(osc_is_ad_page() ? osc_highlight(osc_item_description(), 200) : meta_description()); ?>" />
To get the featured image from the blog post, see the below answer given my MB_themes.
@Peter Petkovski
You say "To get the featured image from the blog post, see the below answer given my MB_themes"
I would like to do this. Can you walk me through this and tell me where to put the code that @MB themes made?
Thanks,
Anthony
-
@Petar Petkovski
I do not think it is ultimate solution, but should work.
$location = Rewrite::newInstance()->get_location();
$section = Rewrite::newInstance()->get_section();
$route = Params::getParam('route');
$img = '';
if ($location == 'blg' && $section == 'article' || $route == 'blg-post') {
$blog_id = Params::getParam('blogId');
$blog = ModelBLG::newInstance()->getBlogDetail($blog_id);
$img = blg_img_link($blog['s_image']);
}
$item_resource_url = ($img <> '' ? $img : $item_resource_url);
@MB Themes
Where are you suggesting that Peter put this code you wrote above? What file and location please?
Thanks,
Anthony
-
@Anthony Marshall
He was talking about oc-includes/osclass/structured-data.php
-
@Anthony Marshall
He was talking about oc-includes/osclass/structured-data.php
@MB Themes
Yes that's what I thought and I tried to put that in there but it did not seem to work for me. I will look into when I get more time.
Peter's statement was "To get the featured image from the blog post, see the below answer given my MB_themes."
That is exactly what I would like to do. Right now if I try to share on social media it just gives the main website logo. If I share an item on social media it will show a picture of the item. What I want is when I share a blog post on social media then it will show the "featured image" that was uploaded when the blog was created.
I know there is some way to do this but I need time to figure it out I guess
Anthony