From 4076324720514817f93e5704324740ac5dbd9585 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:32:12 +1200 Subject: [PATCH] Add fallback featured image (#2555) * :lipstick: Reorder filters and actions alphabetically * Add a default src for featured images and og:image tags * Use versioning instead of a new image Follows the existing practice * Remove jetpack default og:image filter This isn't called if the site has a site icon configured, which prod has --- .../themes/pub/wporg-learn-2024/functions.php | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/wp-content/themes/pub/wporg-learn-2024/functions.php b/wp-content/themes/pub/wporg-learn-2024/functions.php index f870d5720..d047c8e10 100644 --- a/wp-content/themes/pub/wporg-learn-2024/functions.php +++ b/wp-content/themes/pub/wporg-learn-2024/functions.php @@ -18,18 +18,21 @@ */ add_action( 'after_setup_theme', __NAMESPACE__ . '\setup' ); add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' ); -add_filter( 'wporg_block_site_breadcrumbs', __NAMESPACE__ . '\set_site_breadcrumbs' ); -add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' ); -add_filter( 'single_template_hierarchy', __NAMESPACE__ . '\modify_single_template' ); -remove_filter( 'template_include', array( 'Sensei_Templates', 'template_loader' ), 10, 1 ); -add_filter( 'sensei_register_post_type_lesson', function( $args ) { - $args['has_archive'] = 'lessons'; - return $args; -} ); + +add_filter( 'post_thumbnail_html', __NAMESPACE__ . '\set_default_featured_image', 10, 5 ); add_filter( 'sensei_register_post_type_course', function( $args ) { $args['has_archive'] = 'courses'; return $args; } ); +add_filter( 'sensei_register_post_type_lesson', function( $args ) { + $args['has_archive'] = 'lessons'; + return $args; +} ); +add_filter( 'single_template_hierarchy', __NAMESPACE__ . '\modify_single_template' ); +add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' ); +add_filter( 'wporg_block_site_breadcrumbs', __NAMESPACE__ . '\set_site_breadcrumbs' ); + +remove_filter( 'template_include', array( 'Sensei_Templates', 'template_loader' ), 10, 1 ); /** * Modify the single template hierarchy to use customised copies of the Sensei Course Theme templates. @@ -279,3 +282,21 @@ function set_site_breadcrumbs( $breadcrumbs ) { return $breadcrumbs; } + +/** + * Set the default featured image. + * + * @param string $html The HTML for the featured image. + * @param int $post_id The post ID. + * @param int $post_thumbnail_id The post thumbnail ID. + * @param string|array $size The image size. + * @param string|array $attr The image attributes. + * @return string The modified HTML for the featured image. + */ +function set_default_featured_image( $html, $post_id, $post_thumbnail_id, $size, $attr ) { + if ( ! $html ) { + return ''; + } + + return $html; +}