WordPress + Understrap (with SASS + GIT) set up (locally)

Worpress installation.

Download the latest version of WordPress from wordpress.org. Unzip the folder and move the new folder to your sites directory. Rename the wordpress folder to your project name.

Database

Launch phpMyAdmin. Create a new database, user and password. Make a note of these details.

Understrap Theme

Log into WP-Admin. Go to Appearance -> Themes.  Press the Add New button and search for Understrap. Install and activate.

Create Child Theme & set up Visual Studio Code Workspace

Go to the Understrap Child GitHub Project page. Download the project folder. Unzip and move to the wp-content/themes folder.

Rename as per your project.

Open up Visual Studio Code. Select Add Folder to Workspace. Select the new renamed child theme folder and drag into the Explorer window.

Save as new workspace (save this into the main work folder, not the _site folder.

Create new Screenshot.png

Open up a new file in Illustrator or Photoshop – artboard size 880px x 660px. Create new screenshot image and save as wp-content/themes/childtheme/screenshot.png

Edit style.css with theme information

Open up style.css and edit with relevant theme information.

Go into Appearance->Themes and activate the new child theme.

Setting up Sass, JS compilation and BrowserSync

The gulp task ‘watch-bs’ (as defined in gulpfile.js) Starts the Sass watcher (watch), Javascript watcher (scripts) and the browser-sync function.

Custom Javascript

The gulpfile.js identifies the path src/js/custom-javascript.js for custom scripts so create this file and add any custom JS to this file.

Sass

The Gulp watch task monitors any .scss file within any folder within the sass folder (ie assets or themes).

Make any variable changes within _child_theme_variables.scss

Create your own files within the theme directory to simplify things for example:

_header.scss

_navigation.scss

_footer.scss

_utilities.scss

_base.scss

_components.scss

_mixins.scss

You could create an individual folder for each of the pages ie:

sass/pages/_home.scss

sass/pages/_contact.scss

Make sure to @import any custom partials in child-theme.scss

Browser Sync

To utilise browserSync you must configure the proxy option in browserSyncOptions in gulpconfig.json

eg: “proxy” : “localhost:800/randrgardenlandscapes.co,.uk

Compiling using Gulp

First install dependencies (node.js and browsersync must be installed globally)

Open terminal and cd to the theme root folder OR open Terminal->New Terminal in VisualStudio Code and type the following command

npm install

Start Gulp watch, scripts and Browsersync with the following command:

gulp watch-bs

*To stop gulp watch service, press ctrl+C

Setting Up Git

STEP 1: Create local GIT repository
  • Open Terminal
  • CD to root of intended repository
  • type: git init
  • Create a .gitignore file if you don’t want files to be included
STEP 1.2 : Initial Commit
git add -A to add all untracked and modified files
git commit -a -m “initial commit”
Set up remote Repository: BITBUCKET / GIT
STEP 2: Create remote Bitbucket repo
  • Log in to Bitbucket (duncan@samwell.me) / GIT veryselfishman
  • Create a new Repository
STEP 3: Clone and migrate local repo
  • Open terminal and CD to the path of the local repository
  • Type the following code:
git push -u origin master
You can use GitLens in Visual Studio to track, commit and push Git changes.

Setting up Sass

Install Sass in local environment

Create a folder called sass and a file within that called main.scss

(You can use terminal commands (mkdir, touch))

Configuring package.json

Determine how to compile sass by setting scripts in package.json

"scripts": {
 "compile:sass": "node-sass sass/main.scss css/style.css -w"
},

To compile Sass, open terminal and type:  npm run compile:sass

The -w tag will watch for changes within the source file and auto compile.

Live Server

Install using npm

npm install live-server -save

or install globally

sudo npm install live-server -g

type live-server in command prompt and cmd will auto launch

Installing Sass locally using NPM

NPM & the Node Ecosytem

node.js

An open source JavaScript runtime, allows developers write and run JS app on the server. Can also be used to write tools to help with local web development.

NPM

Node Package Manager. Command line interface to allow installation and management of packages on local systems.

Make sure the latest version of node.js is installed (download from node.js website).

node -v on the command line will inform you what version of node.js is on the system.

package.json

First thing to create when creating a new project. Will contain the definitions of the project and where NPM will install the tools and packages its required.

npm init will help you create a package.json file.

You can use pakage.json file to install all the dependencies if you need to work on the project elsewhere, just type npm install

Install Sass

$ npm install node-sass --save-dev

Use NPM to install other dependencies such as jquery (include –save)

npm install jquery --save

This will show in the dependencies (not the devdependencies.

When setting up GIT, make sure to ignore all node_modules so as not to include all the dependencies

Sass – the basics

Features

  • Variables: for reusable values such as colours, font-sizes, spacing, etc;
  • Nesting: To nest selectors inside of one another, allowing us to write less code;
  • Operators: For mathematical operations right inside of CSS;
  • Partials & Imports: To write CSS in different files and importing them all into one single file;
  • Mixins: To write reusable pieces of CSS code;
  • Functions: similar to mixins, with the difference that they produce a value that can then be used; ie darken(color, i%)
  • Extends: To make different selectors inherit declarations that are common to all of them;
  • Control Directives: for writing complex code using conditionals and loops;

Sass syntax vs SCSS syntax

Sass: no requirement for brackets or semi-colons

SCSS similar to traditional CSS, clearer to follow and easier to convert old CSS projects.

Mixins, Functions & Extends

Mixins

ie Clearfix mixin:

@mixin clearfix {
 &::after {
  content: "";
  clear: both;
  display: table;
 }
}

nav {
 @include clearfix;
}

Mixins are groups of CSS that can be reused. Use @include to insert the mixin.

You can also pass arguments through mixins:

@mixin style-link-text($colour) {
 text-decoration: none;
 text-transform: uppercase;
 color: $colour;
}

@include style-link-text(#FFF);

Functions

Functions are like mixins but you can perform mathematical action using arguments passed in parenthesis:

@function divide($a, $b) {
 return $a / $b;
}

Sass has a number of built in functions such as darken() and lighten().

Extends

 

%btn-placeholder {
 styling
}

extend %btn-placeholder

Like mixins, this allows you to reuse code, however instead of copying the code to each element, when compiled it will group all the elements together and apply the style. Use instead of mixins when the elements are related to each other.