Prady
May 31, 2025, 1:13pm
1
I’m trying to create a “Feature” star icon that appears next to each listing (just like when using the HivePress Paid Listings extension).
Instead of integrating with the actual paid listing flow, I simply want to display the star icon button for each listing, which links to a custom URL format like: /pricing?{listing_id}
Is there a recommended PHP snippet or filter hook that I can use to append this custom action link without modifying template files?
Thanks for your guidance!
Hi,
Thanks for the details. You need to use hook hivepress/v1/templates/listing_edit_block
to add any custom content without overwriting the entire template. You can view examples at this link . Also, please see the example of how this is done in Paid Listings: hivepress-paid-listings/includes/components/class-listing-package.php at master · hivepress/hivepress-paid-listings · GitHub .
I hope it helps
1 Like
Prady
June 2, 2025, 11:25am
5
Hey Andrii
Thank you for the amazing explanation
This is what I managed to come up with. Is this correct?
add_filter(
'hivepress/v1/templates/listing_edit_block',
function( $template ) {
return hivepress()->helper->merge_trees(
$template,
[
'blocks' => [
'listing_actions_primary' => [
'blocks' => [
'listing_feature_link' => [
'type' => 'content',
'content' => '<a href="" title="Feature" class="hp-listing__action hp-listing__action--feature hp-link"><i class="hp-icon fas fa-star"></i></a>',
'_order' => 10,
],
],
],
],
]
);
},
1000
);
I’m still struggling to get the desired URL (/pricing?{listing_id}) within the href tag.
Can you please help me with this
andrii
June 3, 2025, 10:17am
8
Hi,
Yes, everything seems to be correct. Additionally, we recommend that you also use the get_the_ID()
function, which will return the listing ID, and you can use it in the href.
Prady
June 4, 2025, 6:33am
9
Thanks for the help again, Andrii
I managed to rewrite the code to get the listing id. Can you please have a look at it?
Is it the right way to do this? Or am I missing something/doing something wrong?
add_filter(
'hivepress/v1/templates/listing_edit_block',
function ( $template ) {
$listing_id = get_the_ID();
if ( ! $listing_id || 'hp_listing' !== get_post_type( $listing_id ) ) {
return $template;
}
$feature_url = add_query_arg(
'listingid',
absint( $listing_id ),
home_url( '/checkout/' )
);
return hivepress()->helper->merge_trees(
$template,
[
'blocks' => [
'listing_actions_primary' => [
'blocks' => [
'listing_feature_link' => [
'type' => 'content',
'content' => sprintf(
'<a href="%s" title="%s" class="hp-listing__action hp-link"><i class="hp-icon fas fa-star"></i></a>',
esc_url( $feature_url ),
esc_attr__( 'Feature' )
),
'_order' => 10,
],
],
],
],
]
);
},
1000
);
Thanks again
andrii
June 4, 2025, 12:10pm
12
Hi,
Yes, this snippet should work correctly. Thank you for sharing it, it will be useful for our community.
1 Like