Skip to content

Commit 1555cc4

Browse files
committed
Improvements in rich snippets and og tags
1 parent 008094d commit 1555cc4

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

Block/Post/View/Opengraph.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public function getImage()
7171
{
7272
$image = $this->getPost()->getOgImage();
7373

74+
if (!$image) {
75+
$image = $this->getPost()->getFeaturedImage();
76+
}
77+
7478
if (!$image) {
7579
$image = $this->getPost()->getFirstImage();
7680
}

Block/Post/View/Richsnippets.php

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public function getOptionsByType($type)
7474
'image' => [
7575
'@type' => 'ImageObject',
7676
'url' => $this->getImage() ?:
77-
($logoBlock ? $logoBlock->getLogoSrc() : ''),
78-
'width' => 720,
79-
'height' => 720,
77+
($logoBlock ? $logoBlock->getLogoSrc() : '')
8078
],
8179
'publisher' => [
8280
'@type' => 'Organization',
@@ -172,4 +170,51 @@ protected function _toHtml()
172170
. json_encode($options)
173171
. '</script>';
174172
}
173+
174+
175+
/**
176+
* Retrieve page title
177+
*
178+
* @return string
179+
*/
180+
public function getTitle()
181+
{
182+
return $this->stripTags(
183+
$this->getPost()->getMetaTitle()
184+
);
185+
}
186+
187+
/**
188+
* Retrieve page short description
189+
*
190+
* @return string
191+
*/
192+
public function getDescription()
193+
{
194+
return $this->stripTags(
195+
$this->getPost()->getMetaDescription()
196+
);
197+
}
198+
199+
/**
200+
* Retrieve page main image
201+
*
202+
* @return string | null
203+
*/
204+
public function getImage()
205+
{
206+
$image = null;
207+
208+
if (!$image) {
209+
$image = $this->getPost()->getFeaturedImage();
210+
}
211+
212+
if (!$image) {
213+
$image = $this->getPost()->getFirstImage();
214+
}
215+
216+
if ($image) {
217+
return $this->stripTags($image);
218+
}
219+
}
175220
}

0 commit comments

Comments
 (0)