Migrate a WordPress installation in less then 5 minutes

Working on a WordPress project I always develop locally. For many projects, there is also a staging server. So migrating WordPress installations is a very frequent task for me. Therefore a good process is key.

Easy migrations without plugins

When I do migrations, I usually always use the WP-CLI. The only requirement for that is an SSH access to the the destination server. My migration process is done with these few steps:

1. Dump the source database

A WordPress installation has two parts, the database and the file system. To dump the database, all you need to do is using the following command in the WordPress document root folder:

wp db export
Success: Exported to 'wp_project-staging-2020-03-29-a2aa75c.sql'.

The file name starts with the database name, followed by the current date and a random hexadeciml hash. This has will come in handy with the second step.

2. Pack all files on the source

Now we are ready to pack all files on the source. This can easily be done with zip, gzip or any similar tool:

zip -r wp_project-staging-2020-03-29-a2aa75c.zip .

As the file name, we simply use the same as the database dump created, just with .zip instead of .sql as the extension. This will “protect” the file name from easily being guessed. Don’t just name it dump.zip as otherwise anyone could just download that file.

3. Transfer the file to the new server

Now it’s time to transfer the file to the new server. This can be done in various ways. A very easy one is using curl, wget or similar:

wget https://staging.example.com/wp_project-staging-2020-03-29-a2aa75c.zip

Transfering from a local system you probaly have to use FTP, as you can’t curl/wget from a local domain.

4. Unpack the file on the destination

The next step is obvious. Once all files are transfered, you have to unpack the files. When you have used a zip files, simply run:

unzip wp_project-staging-2020-03-29-a2aa75c.zip

When you have compressed the files in step 2 in the document root, the files should be unpacked in the document root as well and not be in a subfolder.

5. Update the configuration

Before we can use the project on the new project, we have to update the wp-config.php files. Probably only the values prefixed with DB_.

6. Import the database

Now we can import the database. If the database on the new server is not yet, created, either do it with the management tool of your hoster, or simply by using the WP-CLI as well (which only works, if the database user has the privileges to do this):

wp db create

Once the database is created, you can import is as simply as exporting it in step 1, with the corresponding command:

wp db import wp_project-staging-2020-03-29-a2aa75c.sql

7. Update the domain in the database

As you probably know, in a WordPress installations, all domain paths are stored as absolute paths in the database. This is why you have to update the paths. You can use a plugins for that or also use the WP-CLI with this command:

wp search-replace "https://staging.example.com" "https://example.com"

This is the most basic replacement you have to do. In some cases, you also have to do some other replacements. I will cover that one in a future blog post.

Conclusion

Migrating a WordPress project should be as easy as fast as possible, if you do it on a regular basis. My approach only takes two commands on the source and 4-5 command on the destination. The parts that usually takes the most times is the packing, transfering and unpacking, which will takes longer, the larger a project’s size is. For a small projects all of that might only take less then 10 seconds each.

I hope with this small guide, you next migrations is done as easily and fast as for me. If you have a different approach, that might be handy, please leave a comment below explaining it.

Thank you WordPress community!

The last week was tough. I mean really tough. Just two weeks ago, I thanked event organizers on this blog. Now I see myself in the exact same situation.

The cancellation of WordCamp Europe 2020

On Thursday evening last week, I had a call with Tess and Jonas, the other two global leads of WCEU 2020 and with Rocío, our mentor, as well as Andrea, who is leading the global WordPress community team.

We discussed a timeline for the next weeks and month with a plan to have a WordCamp Europe in Porto in June this year. On 5 March, things were still looking quite OK. There have been only a few cases in Portugal and only Italy had to deal with many cases in Europe. We decided to continue working on the event in June, as we were optimstic to be able to still have it. We planed to wait for early April to get to a decision.

The last days

After that meeting, things have been getting worse every day. Conferences in Europe have been cancelled. On 9 March, a large Joomla conference in Lisbon had been cancelled, just one week before WordCamp Europe 2020 in Porto.

On 11 March, the global community team made the recommendation to postpone of cancelany event until 1 June. As WCEU 2020 was planed for 4-6 June, this was just before that date.

Finally this Thursday, just a week after our “emergecy call”, we had a video call with all organiezers and we decided to cancel WordCamp Europe 2020 and postpone it to 2021 again in Porto.

Thanks to our community

The reactions that have followed our announcement where overwhelming. There was no one disagreeing with our decicion. We have received countless empathic messages on Twitter and through other channels. Many friends from the WordPress communities reached out to me directly, asking how I feel and offering help.

This is why I love this community. In good and in hard times, we support each other and offer help. This is why the organizing team is looking positively into the future and is working even harder for an amazing WordCamp Europe 2021 in Porto.

Thank you WordPress community ❤

Thank you event organizers!

I was planning to write on a different subject today for this week’s #project26 blog post, but due to recent events, I had to write this one today.

WordCamp Asia 2020

February is over, and it was an eventful month for me. Or should I say, it was not? I was really looking forward to my first ever trip to Asia, visiting WordCamp Asia in Bangkok, Thailand. It was scheduled for 21 – 23 February and I have booked my flights and hotel, organized my vacation (as it’s not part of my job to visit WordCamps) and prepared myself for a nice and warm time with many old and new friends. But on 12 February, I got the sad news, that WordCamp Asia had to be canceled.

I was lucky to be able to cancel my hotel and flights without any costs, so I canceled my whole trip to Asia for this year.

CloudFest 2020 Hackathon

This month, from 14 to 16 March, I will be attending my first real Hackaton. It’s not organized only for WordPress community members, but for a broader audience with amazing people from other open source communities and companies specialized in hosting. But I’m also not attending this conference, as CloudFest also has to be canceled.

WordCamp Retreat Soltau 2020

Two years ago, I visited one of my best WordCamps ever. It was not a regular 2-3 days event, where you would meet “from 9 to 5” for talks and workshop, but spend some days all in one hotel 24/7 with not only talks, but also some cool activities. This retreat was planned to take place every two years and was scheduled for 30 April – 3 Mai. It was scheduled, because also this event has to be canceled/postponed to next year just yesterday.

Thank you organizers!

If you now wonder, why I want to thank the organizers, it’s pretty easy. Sure, I’m feeling very sad not to be able to attend all these amazing events … this year. But all organizing teams said, that they want to continue organizing the event in 2021. Most of them in the same places and around the same time.

I have organized four WordPress conferences in Berlin and am currently organizing WordCamp Europe for the fourth time. I know how much work, time, energy and passion goes into organizing these community events. I can only imagine how hard it must have been for all organizers of those WordCamps that had to be canceled (there have been more) and also for the team behind CloudFest, and its hackathon.

With the cancellation of an event, you don’t just stop working. You have to deal with the whole process of canceling any contract and refunding as many people involved as possible. You will also receive some negative feedback from people not understanding the decision (e.g. “there was no case of corona infection in that area”). All organizers involved in those events and the hard decision need our support.

So if you are like me and an event you’ve planned to attend was canceled, take a moment and send a Thank You to the organizing team, as they have made this tough decision in the best interest of the health, both physically and mentally, of our communities. And please support them by attending next year’s event. Maybe even think about becoming a volunteer. This will give you some first-hand experiences on how passionate these organizers are to create these amazing events for all of us.

Thank you event organizers ❤

Repairing image conversation with ImageMagick

Since Version 4.7, WordPress will create a screenshot of the first page of any uploaded PDF file. In order for that to work, ImageMagick and the PHP extension must be installed on the server.

On an Ubuntu 18 webserver I had some WordPress site runnig, the conversion was not working, even though both components were installed. In debugging the issue, I simply tried to do a conversation on the terminal:

convert test-pdf.pdf test-pdf.png

Running the command, I got the following error message:

convert: not authorized `test-pdf.pdf' @ error/constitute.c/ReadImage/412.
convert: no images defined `test-pdf.png' @ error/convert.c/ConvertImageCommand/3210.

After some research I found a solution for the issue. ImageMagick added a security policy some versions ago, which will limit the file types that are allowed to be converted. Unfortunately, the PDF extension is one of those, who can not be converted on Ubuntu 18 by default. But you can simply customize the file /etc/ImageMagick-6/policy.xml which defines the security policies:

<policymap>
  <!-- ... -->
  <policy domain="path" rights="none" pattern="@*" />
  <!-- disable ghostscript format types -->
  <policy domain="coder" rights="none" pattern="PS" />
  <policy domain="coder" rights="none" pattern="EPS" />
  <policy domain="coder" rights="none" pattern="PDF" />
  <policy domain="coder" rights="none" pattern="XPS" />
</policymap>

You can either comment the line with the PDF extension using an XML comment or change the rights to read for PDF:

<policymap>
  <!-- ... -->
  <policy domain="path" rights="none" pattern="@*" />
  <!-- disable ghostscript format types -->
  <policy domain="coder" rights="none" pattern="PS" />
  <policy domain="coder" rights="none" pattern="EPS" />
  <policy domain="coder" rights="read" pattern="PDF" />
  <policy domain="coder" rights="none" pattern="XPS" />
</policymap>

Now you can try again to convert file on the terminal. If the convertion was successful, the comment should not give you any (error) response. If that was successful, upload another PDF into the media library. The screenshot of the first page should now also work there again.

Show missing images from live websites on a development system

When you develop a website, that has already gone live, you usually have to get the latest version of the database to test things. You also need a WordPress system locally with all the plugins and themes that are used on the live website. But how about all the media files that are stored in the uploads folder and that can easily be some gigabytes in size? Well, many times you will need them as well, especially when working on the design. But which ones do you really need locally and how do you keep them up to date with the live website? The good news is: you don’t need to and this blog post will show you an easy way how to solve it differently.

Let’s assume you have just imported a fresh copy of the live database into your local development system. You are probably not seeing some of the files, because as you have updated the URLs in your database to your local domain, those files are not found by the local webserver. You could now connect to the remote server and synchronize the upload folder, potentially downloading many megabytes or gigabyte. If you have multiple projects in development, this will quickly fill up your local hard drive. Or you could just remove the uploads folder alltogether (or at least the uploaded media files in it) and use the files from the live website.

Serve missing files from the live server

For a local environment running on an Apache webserver, you just have to add some lines into your .htaccess files:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wp-content/uploads/(.*) https://xyz.com/wp-content/uploads/$1 [R=302,L]
</IfModule>

Insert this at the beginning of your .htaccess file and it will do the following.

How it works

The Apache webserver will check, if a file or folder exists locally using two RewriteCond statements. If the file/folder is not found, it will use a RewriteRule for all queries to the wp-content/uploads folder and redirect the query to the domain of your live site.

This will effectively load all images from the remote server. If caching headers are set correctly on the live server, the media files will be downloaded only once.

With this little trick, you can see all the lates media files from the live website without the need to download them. You can even edit them in the media library. Once you save changed being made to a file in the media library, WordPress will store a copy of the live version on the local uploads folder including all other generated images sizes. These changes would not be “synced back” to the live website, but you can test changes easily on your local environment.

Some caveats

This approach works perfectly for most cases. But it will not work, if a theme or plugin checks, if a file exists on the server. They will usually use some PHP function to check the upload folder, if the required files does exists. As this fix is solved by the webserver, this PHP check would result in a “miss” of the specfic file.

As most files being checked for existance are usually not stored in the uploads folder, but in folders of the plugins and themes, it should be a huge issue. But in case you ran into such a situation, you have to download the files needed. Finding them might be a bit tricky though.

A second issue is the necessity of a connection to the live webserver. You might work on a website locally, without an internet connection, or a very slow one. While writing this blog post, I’m just taking a train which can result in bad or lost connections. So if you really need the files to work locally, maybe still sychronize some media files.

Does it work for other environments, too?

The same is possible when you use an nginx server in your development environment. But because you usually can not simply add a file to your WordPress document root, you have to add the following lines to your nginx server configuration:

location ~ ^/wp-content/uploads/(.*)$ {
        try_files $uri @missing;
}
location @missing {
	return https://xyz.com$uri;
}

Conclusion

Whenever you make changes to a website, you should work on a local copy. But keeping those copies up to date can be a time and ressource heavy task. In excluding the media files from synchronisations, you can be up running a lot faster and will save a lot of local disk space.

Recude motion on a website for better accessibility

This is my secon blog post in the #FocusAccessibility themed January. Today I want to talk about a topic, that is probably not so common when talking about accessibility. Many of you might know how to optimize websites for visually impaired or blind people. But there are many different types of disabilities. Today I want to hightlight one, that probaly not many of you are aware of.

Motion-triggered vestibular spectrum disorder

The topic is pretty big, although largely unknown. In summary, it means that animations, motions, effects, etc. can harm people viewing a website. I can be a real thread to their health and can lead to epileptic seizure or other symptoms.

Yes, animations and effects are really nice and can make a website even more amazing. But do you really want to harm the visitors of your website? Probably not? But what can you do about it? First of all, get yourself familiar with this issue. There are good articles by Mozilla and A List Apart on that topic. There are also many different elements on your website, that can cause this issue. As I cannot cover all of them, I want to show you a simple way to reduce animations in your CSS code.

The “prefers-reduced-motion” media query

Fortunately modern browsers and operating systems can help you to improve your website to make it less harmful for those users. You can use the prefers-reduced-motion media query to either wrap all of your animations into it and only play them, when the settings is not set by the visitor of your site. Or you disable animations in this media query. You can find more information about that media query on a blog post by CSS-Tricks.

As an example, you can visit the website of WordCamp Europe 2020. The front page has an animation of the logo. Even though the logo is not an extreme example of harmful animations, there might still users who would prefer to have a static logo.

The Design Team of WordCamp Europe did an amazing job creating this animation with pure HTML and CSS code. But the animation was not wrap into the media query. If the CSS code would be wrapped into it, the animation would not start at all and the logo would not become visible. So how can we easily fix is?

“Fast foward” the animation

The fix was pretty easy. I just searched for all elements with a CSS animation on it and “fast fowarded” the animation by setting all delays and durations to zero second, so the logo would be fully visible on page load. The code looks like this:

@media (prefers-reduced-motion: reduce) {
    .wceuicon *,
    .wceuicon:before,
    .wceuicon:after,
    .wceu-logo-text * {
        animation-delay: 0s !important;
        animation-duration: 0s !important;
    }
}

With these few lines, the logo animation is deactivated and the website becomes more accessible.

Reduce the animation

Another solution would be a reduction of the animation. One problematic part of the logo is probably the “blinking cursor” and the “dots flying in”. We could create an animation, where the dots and the cursor would simply fade in on the designated positions in a slow animation. So we still have an animation, but one with a truely reduced motion.

Test the media query

Now you may wonder how to test the new media query. Many modern operating systems offer options. Mozilla has an overview of the supported browsers and where to find the option in different operating systems. On Google’s Developer platform you also find some more useful tips on the media query and how to test them.

Windows 10

If you use Windows 10, you find the option at “Control Panel | Ease of Access |Ease of Access Center | Make the computer easier to see”:

Just activate the “Turn off all unnecessary animations (when possible)” checkbox. This setting will not only recude animations in the browser, but in all programs supporting that setting. After you applied the setting, reload the website with the animation. You should now see the optimized/reduces version.

Android 9

I have also found a setting on my mobile phone. Just search for “accessibility” in the settings. You will then find the switch as “Display | Remove animations”.

There are similar settings on macOS and on iPhones. I was unfortunately not able to find such a settings on my work laptop running on Manjaro linux. But if you know where to find it, please let me know!

Summary

Making a website fully accessible is not an easy task, as many aspects are not as well known as other ones. But when it somes to prioritizing the things to solve first, always start with the things that can harm your visitors. Only then continue with other aspects. I can highly recommend the talk “Prioritizing Accessibility” by Sarah Brodwall from the last Accessibility Club Summit Berlin.

Click here to display content from YouTube.
Learn more in YouTube’s privacy policy.

I hope you have learned a new aspect of accessibility today and I could convice you to use it on your website. If you already have a great reduced animation on one of your sites, please leave a link in the comments, so we can all learn from it.

A few easy steps to make a navigation more accessible

A new year, a new blogging project. Torsten Landsiedel restarted the idea of blogging more regularily. But instead of one blog post per week, he reduced it to one new blog post every two weeks, as well as one comment per two weeks. As I have also participated in previous editions, I will try my best to succeed again. But as this blog is still bilingual, I will post in English in the first week and German in the second week. So I will hopefully post 26 posts, both in English and German.

Focus on Accessibility

Simon Kraft, another long time member of the German WordPress Community, also declared Janurary 2020 to the month with a focus on accessibilty and asks bloggers to focus on that topic. This is why my first two blog posts will have a focus on accessiblity. But probably also some other blog posts this year, as it is a topic I deeply care about.

Accessible navigations

In this first blog post of 2020, I want to show you, how you can easily make your websites navigation more accessible, if it currently is not. The main focus will be on visual and keyboard accessibility.

Improve the visual accessibility

The navigation is maybe the most important element of a website. Both sigthed and visually impaired users will find most sub pages using the navigation. Therefore, the navigation has to be “visually accessible”. Not only for users, but also for assistive technilogies, such as screen readers.

Don’t hide sub menus

When visitors are using a screen reader or similar assistive technology, only elemens that are “visible” will be announced. If a sub menu is hidden using a CSS rule, than those sub menus are not visible to such a visitor.

Hide them differently

For a classical horizontal top navigation, a typical CSS rule may look like this (example from the Yoko theme from Elmastudio):

#branding #mainnav ul ul {
	display: none;
	float: left;
	position: absolute;
	top: 2em;
	left: 0;
	z-index: 99999;
}
#branding #mainnav ul li:hover > ul {
	display: block;
}

The sub menu is hidden by default. On a hover, the display property is switched to block, so the sub menu becomes visible.

Instead of hiding the element, you could move it out of the viewport, so a sighted visitor cannot see it, but a screen reader can:

#branding #mainnav ul ul {
	display: block;
	opacity: 1;
}
#branding #mainnav ul li:not(.focus):not(:hover) > ul {
	position: absolute;
	left: -999em !important;
	opacity: 0 !important;
}

With this code, we show the sub menu on default. We then move the sub menu out of the viewport and set the opcacity to “invisible”, when the top level menu item is not focused and does not have the CSS class focus applied.

Provide a focus style

In order to make the navigation keyboard accessible, it’s not only imporant, that a user can access all item, it is also important to give a visual feedback on the menu item, the visitor is currently navigating to using the keybord.

Unfortunately, many themes globally remove ony outline property from any element. You can either just set the outline for the navigation item back to the default styles, or you simply use the same styles on focus as you use for the hover state. For Yoko it could look like this:

#branding #mainnav ul li a:focus,
#branding #mainnav ul li a.focus {
	background:#F0F0F0;
	color: #999;
}

We set the styles both for the focus state and CSS class, which will help us with the second step.

Improve the keyboard accessibility

In most navigations, the hover state is used to show a sub menu. When using a website with the keyboard only, this state is not triggered or active in CSS. In order to make a navigation usable using the keyboard tab key only, we use some JavaScript, which will add a CSS class focus, when/while a menu item or one of it’s sub menu items is focused:

( function() {
	var container, menu, links, i, len;
	var navigationContainerId = 'mainnav';
	var menuItemFocusedClass  = 'focus';

	container = document.getElementById( navigationContainerId );
	if ( ! container ) {
		return;
	}

	menu = container.getElementsByTagName( 'ul' )[0];

	if ( -1 === menu.className.indexOf( 'nav-menu' ) ) {
		menu.className += ' nav-menu';
	}

	// Get all the link elements within the menu.
	links = menu.getElementsByTagName( 'a' );

	// Each time a menu link is focused or blurred, toggle focus.
	for ( i = 0, len = links.length; i < len; i++ ) {
		links[i].addEventListener( 'focus', toggleFocus, true );
		links[i].addEventListener( 'blur', toggleFocus, true );
	}

	/**
	 * Sets or removes .focus class on an element.
	 */
	function toggleFocus() {
		var self = this;

		// Move up through the ancestors of the current link until we hit .nav-menu.
		while ( -1 === self.className.indexOf( 'nav-menu' ) ) {

			// On li elements toggle the class .focus.
			if ( 'li' === self.tagName.toLowerCase() ) {
				if ( -1 !== self.className.indexOf( 'focus' ) ) {
					self.className = self.className.replace( ' focus', '' );
				} else {
					self.className += ' focus';
				}
			}

			self = self.parentElement;
		}
	}
} )();

When using this snippet, you can simply set the id attribute of the navigation container and the CSS class that should be added on a focus state in lines 3 and 4. This JavaScript does not even need a library like jQuery and should work with any theme that is using the default WordPress navigations and no other JavaScript enhancements on the navigation. This JavaScript is a slighly modified version of code from the _s theme.

With this JavaScript applied, a visitor can use the keyboard to tab-navigate throught the navigation an all it’s sub menus both forward and backward.

Bonus: Improve the usabilty on tablets

Another issue with a hover state horizontal navigation is the fact, that a mobile device like a tablet does not have a hover. When a visitor would click on any top level item, it would only show the sub menu for a split second, before navigating to this top level item.

We want a top level item with a sub menu to show the sub menu on the first click and only navigate on a second click. For top level items without a sub menu, we want those item to navigate on the first click. This can be done with this additional snippet:

( function() {
	var container;
	var navigationContainerId = 'mainnav';
	var menuItemFocusedClass  = 'focus';


	container = document.getElementById( navigationContainerId );
	if ( ! container ) {
		return;
	}

	( function( container ) {
		var touchStartFn, i,
			parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );

		if ( 'ontouchstart' in window ) {
			touchStartFn = function( e ) {
				var menuItem = this.parentNode, i;

				if ( ! menuItem.classList.contains( menuItemFocusedClass ) ) {
					e.preventDefault();
					var menuItemLength = menuItem.parentNode.children.length;
					for ( i = 0; i < menuItemLength; ++i ) {
						if ( menuItem === menuItem.parentNode.children[i] ) {
							continue;
						}
						menuItem.parentNode.children[i].classList.remove( menuItemFocusedClass );
					}
					menuItem.classList.add( menuItemFocusedClass );
				} else {
					menuItem.classList.remove( menuItemFocusedClass );
				}
			};

			var parentLinkLength = parentLink.length;
			for ( i = 0; i < parentLinkLength; ++i ) {
				parentLink[i].addEventListener( 'touchstart', touchStartFn, false );
			}
		}
	}( container ) );
} )();

This snippet will use the ontouchstart event to provide the necessary fixes for a drop down navigation on mobile devices.

Conclusing

It is not really hard to make a website’s navigation accessible. You just have to change your CSS a bit and introduce some JavaScript. This is best done in a child theme. You can also provide the fixes to the initial theme developer, so the fix can be provided to all users of the theme. For the Yoko theme in this example, I have created a small plugin, which bundles all the fixes. Just give it a try! Install the Yoko theme and try to keyboard navigate on your page using only the tab key. Then install and activate the plugin and do the same. Also test the navigation on a tablet using your browsers device emulation function.

After that, test your own theme! Is it accessible? Can you easily make it accessible by using the techniques from this blog post? In case your theme is using a “hamburger menu”, take a look on the code from the _s theme, with provides a very user-friendly and accessible way for a mobile navigation with sub menus.

Allow visitors to call you easily

In the last blog post I wrote about how to customize a web font to add some social media icons to your website. In the project was I’ve mentioned there was the wish to add an icon to call the site’s owner.

Protocols to call from a website

In order to allow visitors to call a number, you simply have to wrap it into a link and use the tel protocol. A link would look like this:

<a href="tel:+1-555-2401">555-2401</a>

In this example, I have used the country code for the US. This is technically not necessary, but it helps when the number might be used from visitors outside of the US. You can add dashes to make the number more readable, but you can also write it like +15552401. The link text can be in any format. It could also be some text like Call us, just as with any other link.

What happens, when clicking the link?

On a mobile phone, as soon as a visitor clicks the link, it will either directly call the number or ask for the app to use, if there is more than one app (like the regular phone app and Skype installed).

And what about desktop browsers?

Even on a desktop browser you can use such links. Here is an example of Chrome, with a left click on the link:

If you have a mobile phone connected to your profile, you can send the phone number from the link to your mobile. Alternatively you can pick another app.

On a right click you can also send the phone number to your mobile, but you don’t habe the option to use a different app:

Alternative protocols

The tel protocoll works for regular phone calls on mobile and desktop. On mobile phone, you can usually also pick a different VoIP app, such as Skype. But on desktop browsers, Skype is not offered. If you want visitors to use Skype, you can use the callto protocol.

There are also the protocols sms and fax, but the browser support is still quite limited.

Conclusion

Offering a link for your visitors to call you is really easy and helps to improve the user experience of your website. You can find an overview on the different browser behaviours and tips and tricks to style such links on CSS-Tricks. So why don’t you add such a link to your website, if you don’t already have one?

Optimize icon web fonts for your needs

On almost any modern website you find icons. They are often used on links to social media profiles. Many WordPress themes come bundled with such a web font for icons. Nowadays I usually always use SVG symbols instead of icon web fonts when building a theme from scratch. But when customizing a theme, you might have to still use them.

Load web fonts locally

Many website owners embed fonts locally due to the GDPR. For this purpose they download the web font and put it into their child theme. Tha’s a perfect time to think about which icons you really need and which not. Icon fonts for social media profiles are a good example on why you might want to customize the font you are including.

Customize a icon web font

Let’s take the popular Font Awesome as an example. It contains 1544 icons with 433 icons for brand such as social media. But do you really have a profile on all of them? If not, it might be worth to only load those icons you really need. With an SVG sprite, that would be as easy as removing al unnecessary symbols from the file, but with web fonts it’s a bit harder.

Online service for font customization

For a friends website I had to add some social media icons the web font bundled with the theme was not providing. So I had to use Font Awesome instead. While searching for a way to use just as few icons as possible I’ve found site Fontello, which offers a variety of icon font. One of them was Font Awesome.

On that website you can simply use the two searches to search for font names and icon names. Then you multi-select all the icons you need. Maybe add some you might need in the near future as well.

On another tab you can even customize the names of the icons in the resulting files and the unicode values. Then simply download your selection, which will contain the web font in different formats as well as some CSS files with the necessary definitions.

Saving a lot of bandwidth

But how much can you safe? Font Awesome uses 3 files for different icon types with 5 formats each. The woff2 files add up to around 165kB. The minified CSS file adds another 57kB.

For that friends website, I only needed 9 icons and woff2 file less then 4kB with another 2kB CSS (unminified), which can be reduced to 1kB (minifed).

In total 2 files/requests and almost 98% in bandwidth (217kB) could be saved.

Do optimize your fonts!

As you can seen, there is a huge potential to safe bandwidth and make your site load faster. The only issue you have to deal with is updating that reduced font, once you need a new icon.

When using Google Fonts, you can use the text parameter to define the characters you need. Unfortunately on Google Fonts you don’t find icon web fonts and I have not found an online service offering a similar functionality. If you know of such a website, please leave a comment below.

Compiling SASS in PhpStorm automatically with a file watcher

In the first post of this litte blog series I showed you how to install SASS manually and how to compile it using the terminal. But this way is not very user friendly and you could easily forget to start the compiler/watch when working on a project.

Adding a file watcher

The easiest way to add the file watcher is by just opening a SASS file. PhpStorm will recognize it and show you a little Notification above the file content. Just click the “Yes” link and the settings screen will open:

If you don’t see the notification, you will find the option to add a file watcher at “File | Settings | Tools | File Watchers”. Here you just click the green plus icon to add a new file watcher and choose SCSS (not Sass, as this would be a file watcher to .sass files, the alternativ syntax, which is less frequently used):

Adjusting the file watcher settings

The default settings are quite good. PhpStorm will most probably find the path to your sass executable. In my case it’s a Windows file path:

One of the options I usually change is the “Arguments” setting. I prefer the expanded output style and not the default nested one, as it looks more like CSS you would usually write manually. My “Arguments” setting looks like this:

--style expanded --no-cache --update $FileName$:$FileNameWithoutExtension$.css

Conclusion

That’s all. Now every time you change your SCSS files (you don’t even have to save them explicitly with the default settings), your files will be compiled into CSS files. The file watcher will even recognize if you change a file that is imported into another file. If you don’t know what that means, just wait for my next blog posts, were I will explain some of the fundamentals of SASS.

Note: If you use the “Tools | Deployment” of PhpStorm to deploy to a FTP server, make sure you activate “Upload external changes” in the “Options” settings, as otherwise the compiled CSS file would not be uploaded.