Skip to content

Frosty-Media/ms-featured-image

Repository files navigation

Multisite Featured Image

Adds a featured image to each site in a WordPress Multisite Network.

Description

This plugin can only be Network Activated.

To stay up to date with this plugin, I suggest installing GitHub Updater

Example Usage

Via a shortcode

This will get all sites in the network, except the ID's passed to the ignore-blog-ids attribute as a comma separated list.

[multisite-featured-image ignore-blog-ids="1,3,5"]

Via a function

This will get the featured image of a specific site in the network. It excepts three parameters and return the URL (string):

namesapce FrostyMedia\MSFeaturedImage;
 
/**
 * Get the attachment image for a specific blog.
 *
 * @param int $blog_id
 * @param string $size Can be any custom image size registered
 *          defaults to 'thumbnail'
 *          optional: medium, large, full
 *          OR array( $size, $size )
 * @param bool $image Use `wp_get_attachment_image` vs `wp_get_attachment_image_src`
 *
 * @return string
 */
function get_site_featured_image( int $blog_id, $size = 'thumbnail', $image = true ): string {
    return Common::getSiteFeaturedImage( $blog_id, $size, $image );
}

Use the function:

use function FrostyMedia\MSFeaturedImage\get_site_featured_image;
 
$current_site_id = get_current_site()->id;
$featured_image = get_site_featured_image( $current_site_id, 'thumbnail' );
echo '<img src="' . esc_url( $featured_image ) . '">';

Or use the method directly:

use FrostyMedia\MSFeaturedImage\Common;
 
$current_site_id = get_current_site()->id;
$featured_image = Common::getSiteFeaturedImage( $current_site_id, 'thumbnail' );
echo '<img src="' . esc_url( $featured_image ) . '">';