Skip to content

Commit

Permalink
Add fallback featured image (#2555)
Browse files Browse the repository at this point in the history
* 💄 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
  • Loading branch information
adamwoodnz authored Jun 20, 2024
1 parent e3a7316 commit 4076324
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions wp-content/themes/pub/wporg-learn-2024/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 '<img src="https://s.w.org/images/learn-thumbnail-fallback.jpg?v=4" alt="" />';
}

return $html;
}

0 comments on commit 4076324

Please sign in to comment.