Custom Icon Configuration
-
Hello! I added a custom “link” icon next to the social media icons, because I want to link to some other sites.
I’d like to make the icon function the same way as the social media icons and the search icon. That is, I’d like it to change to white on hover, but stay purple (#D7AFFF) at all other times, including active and focus.
I’m unsure how to even go about that, because I just found that icon online and made it transparent. Is there a better icon out there that will come with the option to change colors? Is there a link icon built into the theme already that I haven’t found? Or would I need to somehow create a separate white link icon and configure that icon to show up on hover?
And one more thing – Google PageSpeed Insights was telling me that it wants a width and height specified in the code for the custom icon. When I added this icon via the WordPress Customizer, I believe it only specifies width, as shown in the second-to-last line of the code below (found by “Right Click -> Inspect” on the icon):
<img class="icon lazyloaded" src="https://cdn.shortpixel.ai/client/to_avif,q_lossless,ret_img/https://thoughtversation.com/wp-content/uploads/2021/05/Transparent-Link.png" data-src="https://cdn.shortpixel.ai/client/to_avif,q_lossless,ret_img/https://thoughtversation.com/wp-content/uploads/2021/05/Transparent-Link.png" style="width: 24px; max-width: 100%;" data-opt-lazy-loaded="false">So in summary,
1. I’d like to have a custom link icon that can change to white on hover just like the rest of the icons.
2. I’d like the icon to specify both width and height of 24px.Please let me know if this is possible, thanks!
The page I need help with: [log in to see the link]
-
I’m afraid this is a limitation with the custom icons. Since it needs to use an image rather than an icon font, there isn’t a way to modify the icon with :hover.
Are you using ShortPixel’s adaptive images? If so, the missing height attribute shouldn’t be an issue: https://help.shortpixel.com/article/245-i-receive-the-following-image-s-are-missing-width-and-or-height-attributes-when-testing-with-gtmetrix-why
Understood, makes sense. Are there resources to help me learn how to create an icon font with the same functionality as the Facebook and Instagram fonts in your theme, or are those fonts created by the services themselves?
And I’m using Optimole – I’m not sure why the source is from ShortPixel. I know I had used Shortpixel at one point, but I’ve removed it and cleared the cache already.
-
This reply was modified 5 years ago by
epicjono.
Period uses FontAwesome and there is a link icon available, but it’s not added as one of the normal social media icons. The custom icons are basically a fallback for when a social platform doesn’t have an icon supported by Font Awesome yet.
Since you’ve already got a child theme installed, you could copy the
ct_period_social_icons_output()function and manually add the link icon right before the closing</ul>. It’s a bit hacky but would work fine.Thank you for that, I was trying it out and decided to add a “link” option to the ct_period_social_array() and ct_period_social_icons_output() functions, all in my child theme of course. This worked!
'google-wallet' => 'period_google_wallet_profile', 'hacker-news' => 'period_hacker-news_profile', 'imdb' => 'period_imdb_profile', 'link' => 'period_link_profile', 'mastodon' => 'period_mastodon_profile', 'medium' => 'period_medium_profile', 'meetup' => 'period_meetup_profile',} elseif ( $name == 'pocket' ) { $class = 'fab fa-get-pocket'; } elseif ( $name == 'phone' ) { $class = 'fas fa-phone'; } elseif ( $name == 'link' ) { $class = 'fas fa-link'; } else { $class = 'fab fa-' . $name; }Well done! That should work just fine.
Hey Ben, I recently made a TikTok account for my brand, and I want to add a TikTok link. I tried this same method above, but the TikTok icon isn’t appearing. I checked, and there is a TikTok icon in FontAwesome. Any help would be appreciated!
Here’s some relevant code:
function ct_period_social_array() { $social_sites = array( 'twitter' => 'period_twitter_profile', 'facebook' => 'period_facebook_profile', 'instagram' => 'period_instagram_profile', 'linkedin' => 'period_linkedin_profile', 'pinterest' => 'period_pinterest_profile', 'youtube' => 'period_youtube_profile', 'rss' => 'period_rss_profile', 'email' => 'period_email_profile', 'phone' => 'period_phone_profile', 'email-form' => 'period_email_form_profile', 'amazon' => 'period_amazon_profile', 'artstation' => 'period_artstation_profile', 'bandcamp' => 'period_bandcamp_profile', 'behance' => 'period_behance_profile', 'bitbucket' => 'period_bitbucket_profile', 'codepen' => 'period_codepen_profile', 'delicious' => 'period_delicious_profile', 'deviantart' => 'period_deviantart_profile', 'diaspora' => 'period_diaspora_profile', 'digg' => 'period_digg_profile', 'discord' => 'period_discord_profile', 'dribbble' => 'period_dribbble_profile', 'etsy' => 'period_etsy_profile', 'flickr' => 'period_flickr_profile', 'foursquare' => 'period_foursquare_profile', 'github' => 'period_github_profile', 'goodreads' => 'period_goodreads_profile', 'google-wallet' => 'period_google_wallet_profile', 'hacker-news' => 'period_hacker-news_profile', 'imdb' => 'period_imdb_profile', 'link' => 'period_link_profile', 'mastodon' => 'period_mastodon_profile', 'medium' => 'period_medium_profile', 'meetup' => 'period_meetup_profile', 'mixcloud' => 'period_mixcloud_profile', 'ok-ru' => 'period_ok_ru_profile', 'orcid' => 'period_orcid_profile', 'patreon' => 'period_patreon_profile', 'paypal' => 'period_paypal_profile', 'pocket' => 'period_pocket_profile', 'podcast' => 'period_podcast_profile', 'qq' => 'period_qq_profile', 'quora' => 'period_quora_profile', 'ravelry' => 'period_ravelry_profile', 'reddit' => 'period_reddit_profile', 'researchgate' => 'period_researchgate_profile', 'skype' => 'period_skype_profile', 'slack' => 'period_slack_profile', 'slideshare' => 'period_slideshare_profile', 'soundcloud' => 'period_soundcloud_profile', 'spotify' => 'period_spotify_profile', 'snapchat' => 'period_snapchat_profile', 'stack-overflow' => 'period_stack_overflow_profile', 'steam' => 'period_steam_profile', 'strava' => 'period_strava_profile', 'stumbleupon' => 'period_stumbleupon_profile', 'telegram' => 'period_telegram_profile', 'tencent-weibo' => 'period_tencent_weibo_profile', 'TikTok' => 'period_tiktok_profile', 'tumblr' => 'period_tumblr_profile', 'twitch' => 'period_twitch_profile', 'untappd' => 'period_untappd_profile', 'vimeo' => 'period_vimeo_profile', 'vine' => 'period_vine_profile', 'vk' => 'period_vk_profile', 'wechat' => 'period_wechat_profile', 'weibo' => 'period_weibo_profile', 'whatsapp' => 'period_whatsapp_profile', 'xing' => 'period_xing_profile', 'yahoo' => 'period_yahoo_profile', 'yelp' => 'period_yelp_profile', '500px' => 'period_500px_profile', 'social_icon_custom_1' => 'social_icon_custom_1_profile', 'social_icon_custom_2' => 'social_icon_custom_2_profile', 'social_icon_custom_3' => 'social_icon_custom_3_profile' ); return apply_filters( 'ct_period_social_array_filter', $social_sites ); } /* Gets the link icon */ function ct_period_social_icons_output() { // Get the social icons array $social_sites = ct_period_social_array(); // Store only icons with URLs saved $saved = array(); /* Store the site name and ID if saved /* name: twitter /* id: period_twitter_profile */ foreach ( $social_sites as $name => $id ) { if ( strlen( get_theme_mod( $name ) ) > 0 ) { $saved[ $name ] = $id; } } // If there are any social profiles saved if ( !empty( $saved ) ) { echo "<ul class='social-media-icons'>"; // Output list item for every saved profile foreach ( $saved as $name => $id ) { if ( $name == 'rss' ) { $class = 'fas fa-rss'; } elseif ( $name == 'email' ) { $class = 'fas fa-envelope'; } elseif ( $name == 'email-form' ) { $class = 'far fa-envelope'; } elseif ( $name == 'podcast' ) { $class = 'fas fa-podcast'; } elseif ( $name == 'ok-ru' ) { $class = 'fab fa-odnoklassniki'; } elseif ( $name == 'wechat' ) { $class = 'fab fa-weixin'; } elseif ( $name == 'pocket' ) { $class = 'fab fa-get-pocket'; } elseif ( $name == 'phone' ) { $class = 'fas fa-phone'; } elseif ( $name == 'link' ) { $class = 'fas fa-link'; } elseif ( $name == 'TikTok' ) { $class = 'fab fa-tiktok'; } else { $class = 'fab fa-' . $name; } $url = get_theme_mod( $name ); $title = $name; // Escape the URL based on protocol being used if ( $name == 'email' ) { $href = 'mailto:' . antispambot( is_email( $url ) ); $title = antispambot( is_email( $url ) ); } elseif ( $name == 'skype' ) { $href = esc_url( $url, array( 'http', 'https', 'skype' ) ); } elseif ( $name == 'phone' ) { $href = esc_url( $url, array( 'tel' ) ); $title = esc_url( $url, array( 'tel' ) ); } else { $href = esc_url( $url ); } // Output the icon if ( $name == 'social_icon_custom_1' || $name == 'social_icon_custom_2' || $name == 'social_icon_custom_3' ) { ?> <li> <a class="custom-icon" target="_blank" href="<?php echo $href; ?>"> <img class="icon" src="<?php echo esc_url(get_theme_mod($name .'_image')); ?>" style="width: <?php echo absint(get_theme_mod($name . '_size', '20')); ?>px;" /> <span class="screen-reader-text"><?php echo esc_html( get_theme_mod($name . '_name') ); ?></span> </a> </li> <?php } else { ?> <li> <a class="<?php echo esc_attr( $name ); ?>" target="_blank" href="<?php echo $href; ?>"> <i class="<?php echo esc_attr( $class ); ?>" aria-hidden="true" title="<?php echo esc_attr( $title ); ?>"></i> <span class="screen-reader-text"><?php echo esc_html( $title ); ?></span> </a> </li> <?php } } echo "</ul>"; } }Good question. It looks like TikTok was included in a newer version of Font Awesome than is used in Period. I will get an update out soon with a newer version of Font Awesome included.
I would also recommend using “tiktok” in all lowercase to ensure the icon works properly once Font Awesome is updated.
Sorry for the delay. I’ve just submitted an update for Period with the TikTok icon included.
Hey Ben, no problem! I just updated – everything’s working fine except the icon isn’t showing. I tried commenting out all code related to the social media icons, but there’s still an empty space where the icon should be. I can click that space though – just no visual icon.
I can see the icon now: screenshot. I’m guessing it was a caching issue? If you can’t see it on your screen yet, then you likely just need to clear your browser cache to get the new FontAwesome files to load.
Thanks, I always forget about the cache! It’s working now.
Awesome. Glad to hear that!
-
This reply was modified 5 years ago by
The topic ‘Custom Icon Configuration’ is closed to new replies.
