Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.73k stars 881 forks source link

Add a default social image for posts belonging to a taxonomy #21349

Open JosVelasco opened 2 months ago

JosVelasco commented 2 months ago

Is your feature request related to a problem?

Some websites could benefit from adding a default social image to a group of posts. The site-wide fallback image is not enough for big sites.

Describe the solution you'd like

When editing the Social media appearance tag of a taxonomy, add a checkbox to apply these settings to the posts that belong to this group of posts that haven't been assigned something.

Why do you think this feature is something we should consider for the Yoast SEO plugins?

It could complement the social appearance interface and work as a starting point for dynamically generating social images in the style of GitHub cards.

Additional context

I tried to accomplish something similar with this snippet with no luck.

`function custom_og_image( $image ) {

// Check for Yoast user-defined Facebook image if ( empty( $image ) ) { $image = get_post_meta( get_the_ID(), '_yoast_wpseo_opengraph_image', true ); }

// If there is no Yoast image, check for the featured image if ( empty( $image ) ) { $featured_image = get_the_post_thumbnail_url( get_post_thumbnail_id() ); if ( $featured_image ) { $image = $featured_image; } }

// Check for social image in categories (recursive) with fallback to Yoast metafield for category if ( empty( $image ) ) { $image = get_category_image( get_the_category(), $image ); }

// Check for site-wide fallback image (replace 'fallback_image_url' with your actual URL) if ( empty( $image ) && defined( 'FALLBACK_OG_IMAGE' ) ) { $image = FALLBACK_OG_IMAGE; }

return $image; }

add_filter( 'wpseo_opengraph_image', 'custom_og_image' );

// Function to get social image from categories (recursive) using Yoast metafield function get_category_image( $categories, $image ) { foreach ( $categories as $category ) { $cat_meta = get_term_meta( $category->term_id, 'yoast_wpseo_opengraph_image', true ); if ( $cat_meta ) { $image = $cat_meta; break; // Stop searching after finding an image } $parent = get_parent_category( $category ); if ( $parent ) { $image = get_category_image( array( $parent ), $image ); } } return $image; }`

josevarghese commented 2 months ago

Hi @JosVelasco ,

Thank you for suggesting a new feature for one of our plugins! You are the first to have requested this feature!

What's next?  Our development team will assess feature requests in relation to other open bug reports and new features. Based on their assessment, the feature request will be given a priority level. Our developers work on the highest priority first. Unfortunately, this means we cannot give you an estimate if or when they'll start working on your request.