Use CSS Sprites to add social media icons to WordPress

Although there are many plugins that can help you add social media icons to your website, not all all all The plug -in is equal. Some of them may consume your server, let alone low customization.

Fortunately, there is an alternative to help your website maintain lightning -like speed: CSS Sprites.

Generally, a separate image is added to each social media link to the site. Although this is considered a reasonable encoding, it does mean that when the visitor loads the page, the additional server request of each image is required. Of course, the more server requests on the page, the longer the loading time.

The beauty of CSS Sprites is that they can include all images of social media icons, and at the same time they can still mappate all corresponding links. This means less server request, saving bandwidth and fast loading page. A win -win situation!

In this tutorial, I will show you how to use CSS to make your own complete customized social media icon for your WordPress website, including saving some time for you and making the project easier to complete Code.

Continue reading, or use the following link to jump:

Create creation Your image

    Add links and images to your site

  • Add your icon and style

  • Create your image

  • Create creation The first step of your CSS Elf is to create images using social media icons you want to use. It should have two tight stacked layers:

The top layer

-will be visible on the page

  • The underlying layer – Mouse mouse The icon that can be seen when husing
  • This is the example of your icon:

You can customize your icon to suns to you for you The template is perfectly designed.

带有两组图标的社交媒体图标精灵图像。 Please remember that I did not use a transparent background for this image so that they can be clearly displayed in this tutorial. Ideally, the background of the image should be transparent, so that even if you change the style and background color of the theme, you can also use these icons.
You don’t need to add spaces between each image, because C can be used laterSS adds it. This depends entirely on you.

In this example, the icon will be displayed on the site as gray, but when the mouse hovers at When it is on it, its color version will be displayed. After creating your own social media icon set, you can make the next step.

Before continuing, you need to know the width and height of each symbol (in pixels), so be sure to write it down. Image editing program can help you identify this information.

Add links and images to your site

upload the image to your site and write down the position of the image in order to call it in the code later.

Next, you need to add social media links to your website to make these icons play a role. You can use HTML to perform this operation:

Loading points 2C6787171ACCA2FD230E1AC42F3ED025

This is the basic structure required for your link. By replacing

SocialSite

instances and

name of social media site

, add the actual name of the site you want to link. Make sure to replace the URL.

Each icon in the image of the image created by you repeat the second line in the above code above Replace virtual text along the way. You can also choose to change the name of DIV ID to the name that is more suitable for you. The best position to place this code is in the theme file you want to appear directly. For example, you can add the link to

Sidebar.php

, FOOTER.PHP ,

Header.php

or page template files. Don’t be shy. Add the title text with a descriptive title or any other code you want. Don’t forget to save after completion. If your link is not like this, please don’t worry. It doesn’t look beautiful now, but it will soon be.

After the completion, you will not see any difference in your website, but it doesn’t matter, because we have to add pictures next. You can also consider style, filling and spacing later.

默认 TwentyFifteen 主题中未设置样式的基本链接。 I added a standard to the link on my test siteTitle to show you the position of the link.

Add your icons and styles It is time to add your icon with CSS It’s right. If you are willing, you can add the code to the theme style.css file or through custom CSS plug -in.

This is the code you need to add:

Loading points 25468eb49defe2319b9ee3b6de35ddbf Use your own class and image path. You can replace the theme label to the correct value according to your file, but do not change zero -they need to keep it complete to make the icon display correctly.

You can also replicate and paste each other social media icon to be added

SocialSitetwo

. You can also change the location, border, filling, and top to meet your specific style needs.

The following is the subdivision of this CSS example in order to quickly reference:

#Social a.Social {height: #px ;}

-State the theme label to the height of each icon, and is not the total height of the image.

  • #Social a.SocialSiteone {left: 0px;} – This is the position of your first symbol from the left side of the image.
  • #Social a.SocialSiteone {width: #px;}

  • -This is your first social media icon width. For all other icons, this number should be the same.
  • #Social a.SocialSiteone {background: url (\u0026#39; your-image.png \u0026#39;) 0 0;}

  • -I image call is called, image is called, image call is called, and the image is called. The position of the left and top positions is set to zero pixels. #Social a.SocialSitetwo {left: #px;}
  • -Stock theme tags to the pixel value of the starting position of the second icon in the image. If your first icon is 50px wide, then this valueIt’s 51px. #Social a.SocialSitetwo {background: url (\u0026#39; your-image.png \u0026#39;) -#px 0;}
  • -In the theme The tag is replaced with the pixel number of the second symbol from the left side of the image.

  • If the icon you created contains a spacing between the icons in the created, the left side and the background position selectioner will be the same. If you did not add a spacing at first, the left selectioner should be greater than your background position selection device, because you need to consider the spacing to be added, in pixels.

Now you can add images that will be displayed when hanging. For simplicity, you can add the following code below as I do here, or mix them together:

Load the main point F4E57224F380B8FDE98DE81286E4594a

It’s like we are above. In a sample, the theme label is replaced with the correct value. The first value is the number of pixels calculated from the left side, and the second value is the pixel number calculated from the top. After completion, save the file and view the results.

Conclusion

You may need to make some additional adjustments to your CSS style table to achieve the appearance you want, but you have started using this this to use this, but you have already started using this The code introduced.

If you want to know more about CSS to help setting icon styles, please check a article from WordPress beginners to professionals: more than 200 occupations to improve resources and 35 resources, so as to use Become an excellent WordPress developer.

已完成默认 TwentyFifteen 主题中的社交媒体图标。

If you are interested Posts: Use these 5 free WordPress social media plug -in to increase your sharing, 50 best WordPress social media plug -ins (2020).

Editor’s Note: This article has been updated to ensure accuracy and correlation.

[initial release: May 2015 / Amended: April 2022] YouHow to integrate social media into your website or network?Add dialogue and communicate skills at any time, and share your valuable experience in the comments below.

Tags:

Social media

Author:

Leave a Reply

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