PHP code example of doiftrue / wp_term_image

1. Go to this page and download the library: Download doiftrue/wp_term_image library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

doiftrue / wp_term_image example snippets




add_action( 'admin_init', [ \Kama\WP_Term_Image::class, 'init' ] );

add_action( 'admin_init', 'kama_wp_term_image' );

function kama_wp_term_image(){
	
	// Let's specify for which taxonomy it is necessary to set images.
	// It is possible not to specify, then the possibility will be automatically added for all public taxonomies.

	\Kama\WP_Term_Image::init( [
		'taxonomies' => [ 'post_tag' ],
	] );
}

$image_id = \Kama\WP_Term_Image::get_image_id( $term_id );

// OR
$image_id = get_term_meta( $term_id, '_thumbnail_id', 1 );

$image_url = wp_get_attachment_image_url( $image_id, 'thumbnail' );