Last active
August 24, 2022 05:58
-
-
Save wpt00ls/51bdd2fe8a20bdc5474f1bdfc07543a1 to your computer and use it in GitHub Desktop.
Filter to override the category link in the Divi "Post Type" Masonry Gallery
This file contains 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
<?php | |
// Filter to override the categories meta html in the Divi "Post Type" Masonry Gallery | |
add_filter( | |
'wpt_masonry_gallery_post_item_categories_html', | |
function ( | |
$categories_html, | |
$post_item, | |
$post_categories, | |
$link_target | |
) { | |
$response = []; | |
foreach ($post_categories as $category) { | |
$link = get_term_link($category); | |
$name = $category->name; | |
if ($name == 'books') { | |
$name = 'Facebook'; | |
$link = 'https://facebook.com'; | |
} | |
$response[] = sprintf( | |
'<span class="post-category"><a href="%s" target="%s">%s</a></span>', | |
$link, | |
$link_target, | |
$name | |
); | |
} | |
if (!empty($response)) { | |
return sprintf( | |
'<span class="post-categories">%s</span>', | |
implode(', ', $response) | |
); | |
} | |
return $categories_html; | |
}, | |
10, | |
4 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment