Remove [img] & [attach] tags from page meta descriptions

Kevin

Well-known member
When the page meta tags are generated when viewing a thread it seems to be inconsistent when the bb code tags are removed from the descriptions ("description" & "og:description").

For example, on this page http://coolscifi.com/threads/the-amazing-adventures-of-captain-quasar.17952 the first post of the thread starts off using an 'img' tag to embed an image. The description & og:description value in the source is now...
Code:
<meta name="description" content="[IMG]
Hey guys!
Firstly, let me just state for the record, I don't want your money, I'm not here to get funded on kickstarter, I'm not here to beg for..." />
... with the at the front of the text. The same goes for the og:description but since they are identical I'm only copying & pasting the description.

The problem with that is if do something like a Facebook 'Share' button that grabs the og:description value then it ends up like this...

Meta description with leading IMG tag.webp

By contrast it seems like some tags like 'quote' are being gracefully handled by including the quoted text by excluding the [quote] tag from appearing. This page http://awalkerbit.me/threads/constantine.1044/, for example, starts with a sentence followed by a quote. When looking at the source the description is...
Code:
<meta name="description" content="Another comic to TV/movie adaption is in the works, this time DC Comics' Constantine.Neil Marshall (The Descent) is set to direct  NBC’s drama pilot..." />
... which, except for the missing space between "Constantine.Neil", looks much nicer.

Meta description with leading QUOTE tag.webp

Unfortunately it doesn't seem like Facebook allows you to change the description or thumbnail from the shared link so we are at the mercy of whatever the generated og:x tags are.

The request then would be gracefully remove tags like [img] & [attach] from the generated meta tags.
 
Upvote 17
This is kept intentionally because there are cases where the content doesn't necessarily make sense with the non-textual content completely removed. Obviously this isn't always the case, but that's not something that can be detected.
 
This is kept intentionally because there are cases where the content doesn't necessarily make sense with the non-textual content completely removed. Obviously this isn't always the case, but that's not something that can be detected.
So far I'm not finding where it'd be a bad thing to remove img & attach. Is the generation of the description in a spot reachable if we wanted to override it ourselves?
 
It is in the thread_view template:
Code:
<xen:container var="$head.description">
    <meta name="description" content="{xen:helper snippet, $firstPost.message, 155}" /></xen:container>

You'll need to find that else where for various instances.
 
It is in the thread_view template:
Code:
<xen:container var="$head.description">
    <meta name="description" content="{xen:helper snippet, $firstPost.message, 155}" /></xen:container>

You'll need to find that else where for various instances.
Thanks, it looks then that I'd really need to do is override the snippet code & not the HTML.
 
I'm not entirely sure if helpers can be extended and modified without code modifications. I'd have to look into the code to be sure.
 
A trigger in ACP would be nice to stop having this.

Before echo text, substitut <tag>everything</tag>

For you programers this should be a story of five minutes, isnt it?
 
I've been looking for solution to this since the day I installed xenforo. And now I accidentally found this thread while looking for something else. How very XenWhimsical. Please fix this.
 
This is kept intentionally because there are cases where the content doesn't necessarily make sense with the non-textual content completely removed. Obviously this isn't always the case, but that's not something that can be detected.

Is it possible to make an option to toggle the placeholder on or off? I know you guys intentionally included it to ensure the snippets make sense however for the vast majority of web users "attach" doesn't really make sense either as a standalone phrase.

If it cannot be removed perhaps it could be phrased? As in the recent activity the images are below the snippet anyway.

Thanks.
 
Here is what I did.

Create the folder: /library/CustomMeta

Create a file called: descr.php

The contents of the file are:
Code:
<?php

// <xen:callback class="CustomMeta_descr" method="getHTML" params="{xen:helper snippet, $firstPost.message, 155}"></xen:callback>

class CustomMeta_descr
{
    public static function getHTML() 
        {
        $descString = func_get_arg(1);
       
        $descStart = strpos($descString, "[IMG]");

        if ($descStart === false)
            {
            print '<meta name="description" content="' . $descString . '">';
            }
        else
            {
            $descClean = substr($descString, $descStart+5);
            print '<meta name="description" content="' . $descClean . '">';
            }

        }
}

?>

Then in the thread_view template, change the following line:
Code:
<meta name="description" content="{xen:helper snippet, $firstPost.message, 155}" /></xen:container>
to
Code:
<xen:callback class="CustomMeta_descr" method="getHTML" params="{xen:helper snippet, $firstPost.message, 155}"></xen:callback>
 
The presence of img and attach code in snippets has unintended side effects. For example with addons that use the preview snippet and display it on a portal. Like AMS and Showcase.
 
Here is what I did.

Create the folder: /library/CustomMeta

Create a file called: descr.php

The contents of the file are:
Code:
<?php

// <xen:callback class="CustomMeta_descr" method="getHTML" params="{xen:helper snippet, $firstPost.message, 155}"></xen:callback>

class CustomMeta_descr
{
    public static function getHTML()
        {
        $descString = func_get_arg(1);
      
        $descStart = strpos($descString, "[IMG]");

        if ($descStart === false)
            {
            print '<meta name="description" content="' . $descString . '">';
            }
        else
            {
            $descClean = substr($descString, $descStart+5);
            print '<meta name="description" content="' . $descClean . '">';
            }

        }
}

?>

Then in the thread_view template, change the following line:
Code:
<meta name="description" content="{xen:helper snippet, $firstPost.message, 155}" /></xen:container>
to
Code:
<xen:callback class="CustomMeta_descr" method="getHTML" params="{xen:helper snippet, $firstPost.message, 155}"></xen:callback>
Can't make it work to remove my [ATTACH ]'s.
anyone using this method?
 
Here's my method:

Make a new file called Listener.php inside any folder you want within library dir.
For example, mine is in library/EndlessHorizon/Listener.php

Content of Listener.php:
PHP:
<?php

class EndlessHorizon_Listener // make sure this reflects the path, if you put the file in "library/SomeThing", then rename this to "class SomeThing_Listener"
{
    public static function getCleanDesc($content, $params)
    {
        if ($params) { return trim(preg_replace('/(\[[^\[\]]+\]|:\S+:)/', '', $params)); }
        // uncomment line below and comment the line above if you just want it to remove IMG and ATTACH tags
        // if ($params) { return trim(str_replace('[IMG]', '', str_replace('[ATTACH]', '', $params))); }
    }
}

Then edit thread_view template:

Find:
HTML:
<meta name="description" content="{xen:helper snippet, $firstPost.message, 155}" />
Replace with:
HTML:
<xen:set var="$cleanDesc"><xen:callback class="EndlessHorizon_Listener" method="getCleanDesc" params="{xen:helper snippet, $firstPost.message}"></xen:callback></xen:set>
<meta name="description" content="{xen:helper snippet, $cleanDesc, 155}" />

And then, find:
HTML:
<xen:set var="$description">{xen:helper snippet, $firstPost.message, 155}</xen:set>
Replace with:
HTML:
<xen:set var="$description">{xen:helper snippet, $cleanDesc, 155}</xen:set>

Additional notes:
The preg_replace function will remove all BBCode tags. For now it will capture every instance of [whatever]. It will also capture things like this though: [what ever 1 2 3] (so yeah, anything within square brackets, be it letters, number, spaces, symbols, etc. will be captured). I have no idea what's the rule of BBCode tag, so I let it be that way for now.
And it will also capture every instance of :any_non-whitespace_character:, so it should also remove smilies like these: :cool:, :smile:, :sad:, :not_so_sad, :random_0432:, etc.
 
Last edited:
Top Bottom