Make WordPress Core

Opened 5 years ago

Closed 20 months ago

#14113 closed enhancement (wontfix)

Function that could improve the current edit_post_link()

Reported by: metacortex Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Template Keywords: needs-patch
Focuses: Cc:


Basicly this function is the same than edit_post_link() but some little differences which can make it more useful for developers. So far it has two advantages:

1) The edit link can be easily returned.

2) It's possible to choose a class for link tags.

// Returned
function wp_get_edit_link($args = '') {
	$defaults = array(
		'link'   => null,
		'before' => '',
		'after'  => '',
		'id'     => 0,
		'class'  => 'post-edit-link'

	$r = wp_parse_args($args, $predet);

	if ( !$post = &get_post($id) )

	if ( !$url = get_edit_post_link($post->ID) )

	if (null === $link)
		$link = __('Edit This');

	$post_type_obj = get_post_type_object($post->post_type);
	$link = '<a class="'. $class .'" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>';
	return $before . apply_filters('get_edit_link' , $link , $post->ID) . $after;

// Echoed
function wp_edit_link($args = '') {
	echo wp_get_edit_link($args);

Example using the function:


$var = get_wp_edit_link('before=<span class="my-edit-class">&after=</span>&class=my-link-class&link=Edit me!');
echo $var;


<?php wp_edit_link('before=<span class="my-edit-class">&after=</span>&class=my-link-class&link=Edit me!'); ?>

Results on:

<span class="my-edit-class"><a class="my-link-class" href="http://url.to/post.html">Edit me!</a></span>

Change History (5)

comment:1 @metacortex5 years ago

I made a mistake. The string:

$r = wp_parse_args($args, $predet);

Showld be

$r = wp_parse_args($args, $defaults);

comment:2 @metacortex5 years ago

  • Version set to 3.0

comment:3 @nacin5 years ago

  • Keywords needs-patch added

comment:4 @nacin5 years ago

  • Milestone changed from Awaiting Review to Future Release

comment:5 @johnbillion20 months ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

We now have get_edit_post_link() which returns the edit post URL. This should be sufficient as you can craft your own <a> tag around it with whichever class name you like.

Note: See TracTickets for help on using tickets.