Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Set link text auto if not set in wp link picker #4

Closed
trinef opened this issue Dec 12, 2017 · 1 comment
Closed

Set link text auto if not set in wp link picker #4

trinef opened this issue Dec 12, 2017 · 1 comment
Assignees

Comments

@trinef
Copy link

trinef commented Dec 12, 2017

This field: http://d.pr/i/so9ffk
Something like:

/**
 * Get post title from URL if title is empty.
 *
 * @param array $link_values The link field array.
 */
function get_link_field_title( $link_values ) {

        if ( empty( $link_values['title'] ) && false !== strpos( $link_values['url'], home_url() ) ) {
		$linked_post = url_to_postid( $link_values['url'] );
		$link_title  = 0 === $linked_post ? '' : get_the_title( $linked_post );
	} elseif ( empty( $link_values['title'] ) ) {
		$link_title = $link_values['url'];
	} else {
		$link_title = $link_values['title'];
	}
	return $link_title;
}

Maybe it should be a helper function in core?

@trinef trinef self-assigned this Mar 1, 2018
@walbo
Copy link
Collaborator

walbo commented Mar 1, 2018

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants