Add configurable Altmetric badge type via show_altmetric_type parameter#278
Merged
winkm89 merged 3 commits intowinkm89:masterfrom Apr 11, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new shortcode parameter
show_altmetric_typeto all publication list shortcodes (tplist,tpcloud,tpsearch), allowing users to choose which Altmetric badge type to display instead of beinglimited to a hardcoded type.
Problem
The Altmetric embed API supports multiple badge types (
donut,medium-donut,large-donut,bar,medium-bar,large-bar,1,4), as documented at https://badge-docs.altmetric.com/customizations.html#badge-typesPreviously, teachPress had the badge type hardcoded (
large-donutandmedium-donut), with no way to change it without modifying the plugin core directly.Changes
core/publications/templates.phpprepare_altmetric(): added$altm_typeparameter with default value'large-donut'for backward compatibility; appliedesc_attr()to both$doiand$altm_typefor consistency with WordPress codingstandards; removed unused
$doi_urlvariable (dead code)get_infocontainer(): badge type now resolved fromshow_altmetric_typesetting, with fallback to'large-donut'when not setget_images(): same badge type logic applied to the donut/image-area rendering path; removed unused$altmetric_typevariablecore/shortcodes.phpshow_altmetric_typeparameter added to all shortcode definitions (tp_publist_shortcode,tp_cloud_shortcode,tp_list_shortcode,tp_search_shortcode)sanitize_key(), appropriate for the accepted values (lowercase strings and hyphens)show_altmetric_entrx→show_altmetric_entry$count++block that referenced a non-existentshow_dimensions_typesetting, which was incorrectly inflating the colspan calculationBackward Compatibility
Fully backward compatible. When
show_altmetric_typeis not set, behaviour is identical to the previous version.Usage example