diff --git a/FILTERS.md b/FILTERS.md index 9a32cfa5..27dc5db7 100644 --- a/FILTERS.md +++ b/FILTERS.md @@ -97,6 +97,15 @@ Filters the array of breadcrumb tuples inside the `fictioneer_get_breadcrumbs( $ --- +### `apply_filters( 'fictioneer_filter_card_attributes', $post, $context )` +Filters the intermediate output array of HTML attributes inside the `.card` element before they are rendered. The keys are used as attribute names. Make sure to account for already existing attributes. + +**Parameters:** +* $post (WP_Post) – The current post object. +* $context (string|null) - Context regarding where or how the card is rendered. Unsafe. + +--- + ### `apply_filters( 'fictioneer_filter_card_control_icons', $icons, $story_id, $chapter_id )` Filters the intermediate output array of the card control icons inside the `fictioneer_get_card_controls( $story_id, $chapter_id )` function before being rendered. Note that card controls will not be rendered without a story ID. diff --git a/partials/_article-cards.php b/partials/_article-cards.php index b449668a..5d2a24ad 100644 --- a/partials/_article-cards.php +++ b/partials/_article-cards.php @@ -156,8 +156,16 @@ $pag_args = array( $card_classes[] = '_' . get_theme_mod( 'card_style' ); } + // Card attributes + $attributes = apply_filters( 'fictioneer_filter_card_attributes', [], $post, 'shortcode-article-cards' ); + $card_attributes = ''; + + foreach ( $attributes as $key => $value ) { + $card_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" '; + } + // Start HTML ---> ?> -