COMMUNITY FORUM
Meta and OG description improvement
- Ruud van Lent
- Topic Author
- Offline
- New Member
Less
More
8 years 8 months ago - 8 years 8 months ago #153683
by Ruud van Lent
Sharing = Caring
Meta and OG description improvement was created by Ruud van Lent
Hi,
first post here :)
I developed a Joomla! plugin that automatically adds Social Sharing buttons to top / bottom of articles. In last version I have added support for K2.
What the plugin does is add a script to the specified position of the article (or Item when in K2).
the script looks like this:
this works (almost) perfect.
Where this goes wrong is when the article has no meta description and K2 generates one from the intro- or full-text.
K2 uses the following code for this in file ./component/com_k2/views/item/view.html.php
The 'cullprit' is in the strip_tags function.
This strips the tags from the description but does not strip the code itself!
so <script type="javascript/text>herecomesthejquerycode</script> becomes herecomesthejquerycode
When posting that page on Facebook (and G+) the text that is being posted starts with "herecomesthejquerycode'... which is wrong :(
I have solved this with a simple regex. The new code in view.html.php will look like (line 2 is added):
What this code (second preg_replace) does is strip the <script...> and </script> tags AND everything (the script itself) in between :)
Hope this helps!
regards,
Ruud.
first post here :)
I developed a Joomla! plugin that automatically adds Social Sharing buttons to top / bottom of articles. In last version I have added support for K2.
What the plugin does is add a script to the specified position of the article (or Item when in K2).
the script looks like this:
<script type="javascript/text>herecomesthejquerycode</script>
this works (almost) perfect.
Where this goes wrong is when the article has no meta description and K2 generates one from the intro- or full-text.
K2 uses the following code for this in file ./component/com_k2/views/item/view.html.php
$metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext.' '.$item->fulltext);
$metaDescItem = strip_tags($metaDescItem);
$metaDescItem = K2HelperUtilities::characterLimit($metaDescItem, $params->get('metaDescLimit', 150));
$document->setDescription(K2_JVERSION == '15' ? $metaDescItem : $metaDescItem);
The 'cullprit' is in the strip_tags function.
This strips the tags from the description but does not strip the code itself!
so <script type="javascript/text>herecomesthejquerycode</script> becomes herecomesthejquerycode
When posting that page on Facebook (and G+) the text that is being posted starts with "herecomesthejquerycode'... which is wrong :(
I have solved this with a simple regex. The new code in view.html.php will look like (line 2 is added):
$metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext.' '.$item->fulltext);
$metaDescItem = preg_replace("/<script\b[^>]*>(.*?)<\/script>/is", '', $item->introtext.' '.$item->fulltext);
$metaDescItem = strip_tags($metaDescItem);
$metaDescItem = K2HelperUtilities::characterLimit($metaDescItem, $params->get('metaDescLimit', 150));
$document->setDescription(K2_JVERSION == '15' ? $metaDescItem : $metaDescItem);
What this code (second preg_replace) does is strip the <script...> and </script> tags AND everything (the script itself) in between :)
Hope this helps!
regards,
Ruud.
Sharing = Caring
Last edit: 8 years 8 months ago by Ruud van Lent. Reason: typo
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 7 months ago #153710
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Meta and OG description improvement
Hello Ruud,
Kudos on your plugin :) and thank you so much for posting this.
Can you make a PR on Github so we can evaluate and merge it?
github.com/getk2/k2
Kudos on your plugin :) and thank you so much for posting this.
Can you make a PR on Github so we can evaluate and merge it?
github.com/getk2/k2
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Ruud van Lent
- Topic Author
- Offline
- New Member
8 years 7 months ago #153721
by Ruud van Lent
Hi, here you go: github.com/getk2/k2/pull/311
and thanks for the kudos :)
Sharing = Caring
Replied by Ruud van Lent on topic Meta and OG description improvement
Krikor wrote: Hello Ruud,
Kudos on your plugin :) and thank you so much for posting this.
Can you make a PR on Github so we can evaluate and merge it?
github.com/getk2/k2
Hi, here you go: github.com/getk2/k2/pull/311
and thanks for the kudos :)
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 7 months ago #153722
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Meta and OG description improvement
Thanks mate :)
You 'll be notified via Github.
You 'll be notified via Github.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.