0

is it possible to wrap the featured image on the add/edit page in a div or other code? I don't mean on the front page of the website, but on the back end on the add/edit pages when you're typing up your post. I'm trying to add this code around it:

<div id="draggable" class="ui-widget-content">
<p>Featured Image Code</p>
</div>

The code for the featured image is in \wp-admin\includes\post.php but if I add it there it'll be lost when I upgrade.

Thank you!

1
1

When you post this question @PontusAbrahamsson answered you with a good function:

function wpse_111428_change_feature_image_admin( $content ) 
{
    global $post;
    $size = 100;

    $id = get_post_meta( $post->ID, '_thumbnail_id', true );

    if( $id )
    {
        return wp_get_attachment_link( $id, array( $size, $size ) );
    }
}
add_filter( 'admin_post_thumbnail_html', 'wpse_111428_change_feature_image_admin' );

just replace it with a modded version that use code taken from \wp-admin\includes\post.php:

function wpse_111435_change_feature_image_admin( $content, $post_id = null )  {

  $size = 100; // set here your size

  $thumb = $post_id ? get_post_meta( $post_id, '_thumbnail_id', true ) : false;

  if( $thumb ) {
    $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__( 'Set featured image' );
    $set_thumbnail_link .= '" href="%s" id="set-post-thumbnail" class="thickbox">' . __( 'Set featured image' ) . '</a></p>';
    $upload_iframe_src = esc_url( get_upload_iframe_src('image', $post_id ) );

    $content = '<div id="draggable" class="ui-widget-content"><p>' . __('Featured Image Code') . '</p>'; // your html

    $content .= wp_get_attachment_image( $thumb, array( $size, $size ) ) . '</div>'; // this one output the image

    $content .= sprintf( $set_thumbnail_link, $upload_iframe_src );
    $ajax_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post_id );
    $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">';
    return $content . esc_html__( 'Remove featured image' ) . '</a></p>';
  }

  return $content;

}

add_filter( 'admin_post_thumbnail_html', 'wpse_111435_change_feature_image_admin', 20, 2 );
-1

The short answer is no.

The Edit Post screen in WordPress admin only provides the ability for you to upload, edit, and set a featured image for a post or page, but does not provide the ability to change the markup associated with a featured image.

I would suggest adding the code you wish to wrap around your image to your pages template:

<div id="draggable" class="ui-widget-content">
    <p>
        <?php if ( has_post_thumbnail()) : ?>
            <?php the_post_thumbnail(); ?>
        <?php endif; ?>
    </p>
</div>

This should be placed inside of the loop of course.

1
  • 1
    I think short answer is yes. After that, if OP said: > "I don't mean on the front page of the website, but on the back end" why did you say to put code in template files, inside the loop? – gmazzap Aug 24 '13 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.