Developer Tips

Here I intend to provide recipes, patterns, and best practices across the areas I am often asked to help with on my consulting engagements.

Force my Website to use SSL

To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website’s root folder:

RewriteCond %{HTTP_HOST} ^sitedomaingoeshere\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sitedomaingoeshere\.com$
RewriteRule ^/?$ "https\:\/\/sitedomaingoeshere\.com\/" [R=301,L]

Plug in Modules in JavaScript

In JavaScript there is different types of modules. You have Common JS modules, that NodeJS uses by default without even using Bable transpiler. Also there is ES2015 modules with a different plugin syntax. Both are used to bring in modules which can be other JavaScript files, but you also can bring in modules that are installed with NPM.

Common JavaScript modules

Create a simple js file named ‘mymodule.js’:

// make everything in this file available for the other files
module.exports = {
  name: 'Vlad',
  email: ''

In the app file bring this module file in:

const person = require('./mymodule'); // no .js extension!

If you bring in a node module into you app use this:

const person = require('express');

ES2015 JavaScript modules

A slightly different syntax is used for ES2015+:

export const person = { //this variable can be accessed from other files
  name: 'Vlad',
  email: ''

In the app file bring in this module:

import { person } from './mymodule';

If you need to import several variables/functions from one file:

import * as mod from './mymodule';

Exporting default object

The module file:

const greeting = 'Hello';
export default greeting;

In the app use no curly braces:

import greeting from './mymodule';

Calculate person’s age from the date of birth

To calculate a person’s age from the date of birth use vanilla JavaScript:

function Person(dob) {
  this.birthday = new Date(dob);
  this.calculateAge = function() {
    const difference = - this.birthday.getTime();
    const ageDate = new Date(difference);
    return Math.abs(ageDate.getUTCFullYear() - 1970);
const person = new Person('9-10-1990');

Remove the Form on Contact Form 7 WordPress plugin after the submission

To remove form fields on a contact form that uses Contact Form 7 WordPress plugin after the successful submission, add this code to the functions.php file in the WordPress installation:

add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
<script type="text/javascript">
/* <![CDATA[ */
document.addEventListener( 'wpcf7mailsent', function( event ) {
}, false );
/* ]]> */

Display the Woocommerce Product Tags in a simple list

Default setting of the WordPress WooCommerce Product Tag Widget displays the tags in a cloud. If you want to display the tags in a simple list, add the follow code to the function.php file:

add_filter('woocommerce_product_tag_cloud_widget_args', 'nwb_woo_tag_cloud_filter');
function nwb_woo_tag_cloud_filter($args) {
	$args = array(
		'smallest' => 14, 
		'largest' => 14, 
		'format' => 'list', 
		'taxonomy' => 'product_tag', 
		'unit' => 'px', 
	return $args;

Copy a Website from the Internet

HTTrack is a free (GPL, libre/free software) and easy-to-use offline browser utility.

It allows you to download a World Wide Web site from the Internet to a local directory, building recursively all directories, getting HTML, images, and other files from the server to your computer. HTTrack arranges the original site’s relative link-structure. Simply open a page of the “mirrored” website in your browser, and you can browse the site from link to link, as if you were viewing it online. HTTrack can also update an existing mirrored site, and resume interrupted downloads. HTTrack is fully configurable, and has an integrated help system.