Skip to content

Instagram embed regex needs to be extended. #4040

@andrewmatheson

Description

@andrewmatheson

Ran into a case today where the embedded instagram URL was the following:

https://www.instagram.com/tv/Bv4WP9og8YC/

However, this failed the URL_PATTERN regex stored in includes/embeds/class-amp-instagram-embed.php

const URL_PATTERN    = '#http(s?)://(www\.)?instagr(\.am|am\.com)/p/([^/?]+)#i';

The regex expects the URL to have a 'p' in the URL but instagram now also allows a 'tv' in the same position. If you use either URL version in a browser the same page is displayed.

Changing the URL in the embed to use the 'p' version allowed the embed to work in AMP, however the regex should probably be adapted to accommodate the new URL format. Something like the following:

const URL_PATTERN    = '#http(s?)://(www\.)?instagr(\.am|am\.com)/(p|tv)/([^/?]+)#i';

I've tested this change on my own sites and it does what I expect (accepting either 'p' or 'tv' in the URL).


Do not alter or remove anything below. The following sections will be managed by moderators only.

QA testing instructions

  1. Add an Instagram block to a page with the URL: https://www.instagram.com/tv/Bv4WP9og8YC/

  2. Embedded Instagram post should be visible on page

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingEmbedsQA passedHas passed QA and is done

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions