Skip to content

Release 2.8.2

Latest
Compare
Choose a tag to compare
@gsarig gsarig released this 02 Jun 22:10

Version 2.8.2 is a follow-up to the new feature of the "Location" custom field, introduced in version 2.8.0, following the request on #49. It adds two new hooks, which allow you to fully change the contents of a marker's modal box as well as its icon, when the new "OpenStreetMap from custom fields" block is used. This can be very powerful, as it allows you to fully modify the content displayed in your markers' modals, even using your own custom fields to display extra information. The hooks are:

ootb_cf_modal_content

Allows you to change the content of the modal that appears when you query posts based on their "Location" custom fields. By default, it will display the value set in the Address field. For example, the following code will display the post's title, thumbnail, excerpt and a link to the post:

add_filter( 'ootb_cf_modal_content', 'my_modal_content', 10, 2 );

function my_modal_content( $address, $post_id ) {

	return sprintf(
		'<div>
			<h3>%1$s</h3>
			<figure>%2$s</figure>
			<p>%3$s</p>
			<p><a href="%4$s">View post</a></p>
		</div>',
		get_the_title( $post_id ),
		get_the_post_thumbnail( $post_id, 'thumbnail' ),
		has_excerpt( $post_id ) ? get_the_excerpt( $post_id ) : $address,
		get_the_permalink( $post_id )
	);
}

ootb_cf_marker_icon

Allows you to change the marker icon for posts that have a "Location" custom field. By default, it will use the default marker. For example, the following code will use a custom marker for a post with ID 123:

add_filter( 'ootb_cf_marker_icon', 'my_marker_icon', 10, 2 );

function my_marker_icon( $icon_url, $post_id ){
	if( 123 === $post_id ) {
		$icon_url = 'https://example.com/my-marker.jpg';
	}
	return $icon_url;
}

For the most up to date info about the available hooks, see the 🪝hooks section.