Since: 3.1.4
File: includes/wp-geo.php
Param: $title Point title (defaults to post title)
Param: $post_id Post ID

By default the tooltip for markers will display the post title. The wpgeo_point_title filter lets you override this value so you can set different text for the tooltip.

The filter accepts two arguments. The first is the default marker title which you can override or add to. The second argument is the ID of the post – you could use to get some post meta data to display as the title.

Example 1

function my_wpgeo_point_title( $title, $post_id ) {
	// Add a prefix to the point title
	return 'My Point: ' . $title;
}
add_filter( 'wpgeo_point_title', 'my_wpgeo_point_title' );

Example 2

function my_wpgeo_point_title( $title, $post_id ) {
	// Add a coordinates to the point title
	$latitude  = get_post_meta($post_id, WPGEO_LATITUDE_META, true);
	$longitude = get_post_meta($post_id, WPGEO_LONGITUDE_META, true);
	return $title . ' (' . $latitude . ', ' . $longitude . ')';
}
add_filter( 'wpgeo_point_title', 'my_wpgeo_point_title' );

6 Responses to “wpgeo_point_title”

  1. Sacha says:

    Hi Ben,

    I tried the code you posted (ex 1 and 2) but I receive this error:
    Warning: Missing argument 2 for my_wpgeo_point_title()

    What do you think it can be?
    Thanks in advance

    • Sacha says:

      Hi Ben,

      I removed $post_id from the function and it worked.

      Another question though: i’d like to add some html, like
      return ‘My Point: ‘ . $title;

      but the html gets escaped.

      Is there any other approach I can follow? I already tried with
      return ‘My Point: <br /> ‘ . $title;
      with no success.

      Thanks
      Sacha

  2. Matt M says:

    I am having difficulties using this. It seems that no second parameter is being passed in. Therefore it’s not possible to use Post ID within the tooltip. For example, I I try to use this:

    function my_wpgeo_point_title( $title, $post_id ) {
    $longitude = get_post_meta($post_id, WPGEO_LONGITUDE_META, true);
    return $title . ‘ (Post ID=’ . $post_id . ‘)’;
    }
    add_filter( ‘wpgeo_point_title’, ‘my_wpgeo_point_title’ );

    The tool tip ends up with a blank Post ID. What am I doing wrong?

    • benhuson says:

      When adding a filter, if you need the post IDbyou need to specify that the callback should expect 2 parameters.

      add_filter( ‘wpgeo_point_title’, ‘my_wpgeo_point_title’, 10, 2 );

  3. Jake Nelson says:

    It looks like the plugin has been restructured since this post, where can I find this function as of version 3.4? Thanks! Love the plugin 🙂

    • benhuson says:

      The `wpgeo_point_title` filter still exists.

      The functions mentioned above are custom functions (not part of the plugin) to show how to hook into the `wpgeo_point_title` to adjust the output.

Leave a Reply