• Hello everyone… what I am attempting to do I feel should be relatively simple, but I have yet to really learn how to use WP filters. So if someone could, please show me how I would go about adding an addition class attribute to the “edit_post_link” filter.

    edit_post_link is located at wp-includes/link-template.php:

    function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
    	if ( !$post = &get_post( $id ) )
    		return;
    
    	if ( !$url = get_edit_post_link( $post->ID ) )
    		return;
    
    	if ( null === $link )
    		$link = __('Edit This');
    
    	$post_type_obj = get_post_type_object( $post->post_type );
    	$link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>';
    	echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Ryan

    (@daobydesign)

    I don’t believe there’s any built in method to do this, so the only way would be to add a filter and modifying the output via a custom function by dropping something like the following in your theme’s functions.php file:

    function custom_edit_post_link($output) {
        $output = str_replace('class="post-edit-link"', 'class="post-edit-link your-class', $output);
    }
    add_filter('edit_post_link', 'custom_edit_post_link');

    Hope it helps.

    Building on that last very useful reply, correcting a typo and adding a line that slipped his mind, we get:

    //Add class to edit button
    function custom_edit_post_link($output) {
     $output = str_replace('class="post-edit-link"', 'class="post-edit-link your-class"', $output);
     return $output;
    }
    add_filter('edit_post_link', 'custom_edit_post_link');
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘add class to –> edit_post_link’ is closed to new replies.