• Resolved maxxnz

    (@maxxnz)


    Is it possible to automatically strip HTML from image captions? Or to ensure that links within captions are functioning correctly?

    Currently we have some captions that contain HTML (usually just < a href > for links), which when they are being output to Facebook Instant Articles, the raw HTML code is showing up. I would prefer to either remove the HTML entirely, or even better have the links function correctly.

    Strangely enough it seems to be only the main image at the top of the article (the featured/thumbnail image) where this issue is occurring. The inline images (within the body text) have links which are working correctly.

    Screenshot of this happening: https://mixdev.nz/clients/misc/IMG_4616.PNG

    https://www.ads-software.com/plugins/fb-instant-articles/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi, maxxnz. Thanks for the screenshot of what you described.

    Purposefully, tags in captions are escaped since links aren’t allowed on image captions.

    As for stripping the tags altogether, I think this would be possible by customizing the Rules for the Transformer.

    The plugin makes use of the Facebook Instant Articles SDK for PHP which contains a Transformer that does all the heavy lifting of converting general markup into valid Instant Articles markup — and it, of course, is fully customizable since it uses a set of rules for specifying how to parse the content of the post/page. In the plugin, you can define your own rule set in the Settings page of the plugin under: Plugin Configuration > Publishing Settings > Custom transformer rules.

    I think you’d be interested in associating a selector for anchor tags within image captions to a PassThroughRule.

    For more information please the Selector Rules section of our Quick Start guide.

    I’ll leave this item open until I hear back from you with your thoughts or results.

    Thanks again!

    Thread Starter maxxnz

    (@maxxnz)

    Hi demoive, thanks for your reply.

    You mentioned that “tags in captions are escaped since links aren’t allowed on image captions” – however the rest of our images in the Instant Articles are showing up with their links intact. Is there a chance the code isn’t getting stripped correctly on the whole? And if these links are showing up, is that likely to fail Facebook’s review method?

    It looks like the Transformer rules only apply to the content of the post. They don’t affect elements in the Header, like the main image caption that maxxnz mentioned.

    @maxxnz, actually, it was my mistake when I mentioned that tags in captions are escaped. You are correct to mention that they are not escaped.

    So that I can better debug and reproduce this, could you provide some links to example articles (if you have them live) which contain image captions with links? You also mentioned that for some of your articles, the link renders as expected — is this true and if so, could you also provide a link to an example so we can try to differentiate?

    Additionally, it would be great if you can provide the debug output shown in the post edit screen on the Facebook Instant Article box (both sides after clicking the “toggle debug information” link).

    Thanks again.

    Paulo,

    We use links in captions without any issues, Facebook doesn’t return any errors on this, however for us to use this functionality we do write our own shortcode for galleries. Do you have any links to Facebook documentations that reflect no links allowed?

    @gemedet, yes you’re correct in that the Transformer Rules are only applied to the body of the post. The additional information needed to generate the Instant Article (such as the Header you’ve already mentioned) is acquired WordPress meta data directly.

    Hi @sbshields9. Actually, links within captions are allowed and supported. I’ve tested this to confirm so you shouldn’t have any problem using links in your image captions.

    If you use shortcodes, you might have to look into creating your own Custom Transformer Rules to make sure they are converted properly into an Instant Article.

    @paulo, What about links within the caption in the Header? To apply the Transformer rules to it, take a look at this pull request.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Remove HTML from image captions’ is closed to new replies.