Make WordPress Core

Opened 3 years ago

Last modified 2 years ago

#23570 closed enhancement

Add functions to extract a URL from an arbitrary string, HTML, or the current $post — at Version 4

Reported by: wonderboymusic Owned by:
Milestone: 3.6 Priority: normal
Severity: normal Version:
Component: Post Formats Keywords: has-unit-tests needs-codex
Focuses: Cc:

Description (last modified by wonderboymusic)


My post has a format of "link"

  • My post has format meta for URL
  • OR - My post content is a URL
  • OR - My post contains an <a> tag with an href
  • OR - My post content is a URL followed by new line(s) and commentary

An arbitrary string might be only a URL, a URL with some commentary, or a blob of HTML that might contain an <a> with an href attribute

Introduce the_link() and get_the_link( $id = 0 ) which will arbitrarily extract a URL from a post's content.

Introduce get_content_link( &$content, $remove = false ) to find a URL in an arbitrary string meeting the above criteria and optionally remove the found URL if it wasn't embedded in HTML content.

Change History (7)

@wonderboymusic3 years ago

comment:1 @helen3 years ago

  • Component changed from General to Post Formats

Sort of Template, sort of Post Formats. Putting it in Post Formats for easy tracking of the feature dev.

comment:2 @lancewillett3 years ago

  • Cc lancewillett added

comment:3 @lancewillett3 years ago

For support of new functionality in default themes, see:

  • Twenty Eleven: link post format - #23618
  • Twenty Thirteen: link post format - #23619

@wonderboymusic2 years ago

comment:4 @wonderboymusic2 years ago

  • Description modified (diff)

attachment:23570.2.diff​ is patch refreshed against trunk and tested compatibility for these 6 scenarios:

  • Post with the link as the content
  • Post with the link as the content, followed by commentary
  • Post with the link as the content AND has link meta value
  • Post with the link as the content AND has link meta value, followed by commentary
  • Post with the link as metadata, content is empty
  • Post with the link as metadata, followed by commentary

If the theme supports structured-post-formats, nothing happens to the content.
The themer can use: the_link(), get_the_link(), and get_content_link( $content ) - all return a URL. get_content_link( $content ) only works if the link is in the post's body.

If the post has a post format of link, the compat runs whether the theme supports it or not.

@Frank Klein2 years ago

Note: See TracTickets for help on using tickets.