Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




set_post_thumbnail [ WordPress Function ]

set_post_thumbnail ( $post, $thumbnail_id )
Parameters:
  • (int|object) $post Post ID or object where thumbnail should be attached.
  • (int) $thumbnail_id Thumbnail to attach.
Returns:
  • (bool) True on success, false on failure.
Defined at:



Sets a post thumbnail.

Source


<?php
function set_post_thumbnail$post$thumbnail_id ) {
    
$post get_post$post );
    
$thumbnail_id absint$thumbnail_id );
    if ( 
$post && $thumbnail_id && get_post$thumbnail_id ) ) {
        
$thumbnail_html wp_get_attachment_image$thumbnail_id'thumbnail' );
        if ( ! empty( 
$thumbnail_html ) ) {
            return 
update_post_meta$post->ID'_thumbnail_id'$thumbnail_id );
        }
    }
    return 
false;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics