Swapping out Font Awesome Icons in a TTG page

gallery with globe icons
Gallery GPS icons swapped out for globe icons

Recently on the TTG Community Forum, a user asked about being able to replace the standard GPS Google Map marker icon used in TTG CE3 Gallery with a globe icon, like the one that was used with the CE2 version of TTG Gallery.

The gps icon, like all icons in CE3 is a Font Awesome icon (icon-map-marker). And it looks like it’s hard coded into the TTG CE3 Gallery web-engine. So we’re looking to replace that icon with something else. Turns out there is a globe Font Awesome icon that will serve the purpose (icon-globe) .

Since Font Awesome icons are placed using the code <i class="icon-name-of-icon"></i> ( a class applied to the “i” html tag) that means we need to replace the existing class named “icon-map-marker” with the “icon-globe” class.
I can think of one relatively easy way to remove and add classes and that’s using JQuery. I’ll use a little snippet of code to remove the class “icon-map-marker” from that “i” tag then add the class “icon-globe” to it.
Here’s the code:


<script>
$(document).ready(function(){
$(".map-marker i").removeClass("icon-map-marker").addClass("icon-globe");
});
</script>

Here’s what’s happening. That first part, the <script> tag, is needed to tell the browser that a script is coming. The first line of the actual script just tells jQuery to wait until the page loads before executing what follows.
The magic happens in the next line. The script is basically saying: Look for the indicated selector (in this case, the “i” tag inside of a class named “map-marker”), remove the class “icon-map-marker” from the tag and add the class “icon-globe”.
Next, the closing </script> tag tells the browser that the script is ended.

To accomplish this, you’ll first need to enable phplugins. The instructions for doing so can be found here. Once you’ve done this, open your global phplugins.php file with a plain text editor and insert the above code using the ttg_head_end hook. You can just add the code right after the code that enables custom css. You’ll see this once you open the phplugins.php file.
You can learn more about editing and using phplugins starting here.

The whole thing inside of the ttg_head_end function in the phplugins.php file will look like this:


function ttg_head_end( $style, $path ) {
echo '
<link href="/phplugins/css/custom.css" rel="stylesheet" />

<script>
$(document).ready(function(){
$(".map-marker i").removeClass("icon-map-marker").addClass("icon-globe");
});
</script>
'; //script to swap Font Awesome GPS icons
} // END

And you can see it working on a test gallery I’ve posted here.

2 thoughts on “Swapping out Font Awesome Icons in a TTG page”

  1. Rod,

    Thanks for the great article on swapping the GPS map marker in TTG Gallery.

    I have a darker background in my gallery, and the marker has a white background. Do you know of any way to changer the marker’s background or to make the background transparent?

    Thanks!

    Dave

    1. You can control the icon’s background color in the Gallery plug-in under Appearance > Grid Icons. If you wanted transparency you’d need to use custom css.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Newsletter

Take a look through the Newsletter archives or subscribe.

Keep up to date on workshop offerings, print sales, photo tips, puppy pictures and more!



Affiliate links below! If you buy after clicking these links, I get a taste. Win-win!

Maven Filters


High quality magnetic photo filters that will change your photographic life!
Affiliate link.


Topaz Labs

Awesome plug-ins to reduce noise, sharpen, and resize images. Affiliate link!


Think Tank

Affiliate link!

Lightroom Classic The Missing FAQ

Highly recommended. This is my go-to Lightroom book. Click on the book image. Affiliate link!