Blog Post Structured Data
« 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

Code: [Select]
<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:

Code: [Select]
<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.
« Last Edit: March 04, 2021, 03:16:32 PM by Petar Petkovski »

Marked as best answer by petar.petkovski on March 04, 2021, 03:15:56 PM
*

MB Themes

Re: Blog Post Structured Data
« Reply #1 on: March 04, 2021, 02:38:03 PM »
@Petar Petkovski
I do not think it is ultimate solution, but should work.
Code: [Select]
  $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);
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Re: Blog Post Structured Data
« Reply #2 on: March 04, 2021, 03:09:50 PM »
This solution works fine and I can see that

Code: [Select]
<meta name="twitter:image" content="<?php echo $item_resource_url?>" />

and

Code: [Select]
<meta property="og:image" content="<?php echo $item_resource_url?>" />
are correctly returning the blog featured image :)
« Last Edit: March 04, 2021, 03:15:36 PM by Petar Petkovski »

*

MB Themes

Re: Blog Post Structured Data
« Reply #3 on: March 05, 2021, 07:45:11 AM »
@Petar Petkovski
Cool ;)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Re: Blog Post Structured Data
« Reply #4 on: March 08, 2021, 03:45:33 PM »
@Petar Petkovski
I do not think it is ultimate solution, but should work.
Code: [Select]
  $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?
« Last Edit: March 08, 2021, 03:48:06 PM by Anthony Marshall »

*

MB Themes

Re: Blog Post Structured Data
« Reply #5 on: March 08, 2021, 04:05:56 PM »
@Anthony Marshall
It is not possible to use image that is just in content
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Re: Blog Post Structured Data
« Reply #6 on: March 08, 2021, 04:10:20 PM »
@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?

Re: Blog Post Structured Data
« Reply #7 on: March 08, 2021, 04:34:31 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

Code: [Select]
<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:

Code: [Select]
<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

Re: Blog Post Structured Data
« Reply #8 on: March 08, 2021, 04:43:51 PM »
@Petar Petkovski
I do not think it is ultimate solution, but should work.
Code: [Select]
  $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

*

MB Themes

Re: Blog Post Structured Data
« Reply #9 on: March 08, 2021, 04:54:08 PM »
@Anthony Marshall
He was talking about oc-includes/osclass/structured-data.php
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Re: Blog Post Structured Data
« Reply #10 on: March 08, 2021, 05:03:16 PM »
@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