Help Desk

Change Template tag for Google Maps

  • Posts: 14 Topics: 6
    | Permalink

    My goal is to change the text for the maps link. I have looked through the Themer’s Guide and haven’t seem how to do this. I have found the code in functions/template-tags/google-map.php on line 47. I tried copying the function and placing it in my functions.php, but that just throws an error saying that the function was already created. What is the best way for me to make this change? I know that there should be a way around editing the plugin file. Thanks for the help I appreciate it.

    Posts: 39
    | Permalink

    Hi Shea,

    I believe I can help you out with this.

    You are correct that you don’t want to copy the function and put it into functions.php but I do believe you are looking in the right place.

    If I can ask you a quick question, what text is it that you want to change? Is it: ‘Click to view a Google Map’?  If so, it is in the functions/template-tags/google-map.php on line 46 (right where you were looking),  You can change it there with no issues.  If it is other text, let me know!

    Thanks,

    Ron

    Posts: 14 Topics: 6
    | Permalink

    Hi Ron,

    I actually want to change the ‘+ Google Map’ text that is on line 47. I must have grabbed the wrong line number before. If I change the text there, what will happen when the update gets run on the plugin? Would I lose those text changes? If possible I would like to avoid having to make those changes everytime I update.

    Thanks for the help.

    Posts: 39
    | Permalink

    Hi Shea,

    There are a couple possible solutions to this. The first is to change it where we discussed, but as you guessed, this will be overwritten when you update. Another option is to add a snippet to your themes functions.php file. This is what you would add:

    < ?php add_filter( 'tribe_get_map_link_html', 'override_tribe_get_map_link_html' ); function override_tribe_get_map_link_html( $html ) { $html = sprintf( '%s‘,
    esc_url( tribe_get_map_link( $postId ) ),
    esc_html__( ‘Click to view a Google Map’, ‘the-events-calendar’ ),
    ‘MY NEW STRING!’

    );
    return $html;
    }

    ?>

    This is untested but I think you get the idea?

    Posts: 14 Topics: 6
    | Permalink

    Hi Ronald,

    That is awesome! With a little tweaking I was able to get the code to work. Here is the working code:

    add_filter( 'tribe_get_map_link_html', 'override_tribe_get_map_link_html' ); 
    function override_tribe_get_map_link_html( $html ) { 
    	$html = sprintf( '<a class="tribe-events-gmap" href="%s" title="%s" target="_blank">%s</a>',
    		esc_url( tribe_get_map_link( $postId ) ),
    		esc_html__( '+ Google Map', 'the-events-calendar' ),
    		'map'
    	);
    	return $html;
    }

    Thanks so much for the help. I really appreciate it.

    Posts: 39
    | Permalink

    No problem Shea! I’m glad I could help, and thanks for your help!

    Posts: 65
    | Permalink

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.