1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'XenForo Suggestions' started by Kevin, Jan 31, 2014.

  1. Kevin

    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...
    <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.JPG

    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...
    <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.JPG

    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.
    otto, kralseyit66, semprot and 14 others like this.
  2. Mike

    Mike XenForo Developer Staff Member

    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.
  3. Kevin

    Kevin Well-Known Member

    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?
  4. Jeremy

    Jeremy Well-Known Member

    It is in the thread_view template:
    <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.
  5. Kevin

    Kevin Well-Known Member

    Thanks, it looks then that I'd really need to do is override the snippet code & not the HTML.
  6. Jeremy

    Jeremy Well-Known Member

    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.
    Kevin likes this.
  7. Robert9

    Robert9 Active Member

    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?
  8. russoroni

    russoroni Active Member

    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.
    CNK likes this.
  9. maxicep

    maxicep Active Member

    Same here.

    IMG Tags should be remove from meta descriptions !
    rafass, CNK, Firarist and 1 other person like this.
  10. Ferdinand

    Ferdinand Active Member

    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.

    russoroni likes this.
  11. CNK

    CNK Active Member

    has anyone solved this problem?
  12. Kevin Remer

    Kevin Remer New Member

    Here is what I did.

    Create the folder: /library/CustomMeta

    Create a file called: descr.php

    The contents of the file are:
    // <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 . '">';
                $descClean = substr($descString, $descStart+5);
                print '<meta name="description" content="' . $descClean . '">';
    Then in the thread_view template, change the following line:
    <meta name="description" content="{xen:helper snippet, $firstPost.message, 155}" /></xen:container>
    <xen:callback class="CustomMeta_descr" method="getHTML" params="{xen:helper snippet, $firstPost.message, 155}"></xen:callback>
  13. Alfa1

    Alfa1 Well-Known Member

    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.
  14. rafass

    rafass Well-Known Member

    Can't make it work to remove my [ATTACH ]'s.
    anyone using this method?
  15. BobbyWibowo

    BobbyWibowo Well-Known Member

    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:

    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 
            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:

    <meta name="description" content="{xen:helper snippet, $firstPost.message, 155}" />
    Replace with:
    <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:
    <xen:set var="$description">{xen:helper snippet, $firstPost.message, 155}</xen:set>
    Replace with:
    <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: May 26, 2016
    rafass likes this.

Share This Page