Skip to content

Instantly share code, notes, and snippets.

View jamestrevorlees's full-sized avatar

James Lees jamestrevorlees

  • Advantage Learn + Pango
  • Durban, South Africa
View GitHub Profile
@jamestrevorlees
jamestrevorlees / Plugin Test Function
Created June 30, 2016 09:58
php code to test whether WordPress plugin is activated
<?php
/*
Plugin Name: My Cool Name
Plugin URI: https://jamestrevorlees.me/my-first-plugin
Description: This is my first WordPress Plugin
Author: James Lees
Author URI: https://jamestrevorlees.me
Version: 1.0
*/
//Create function for plugin test
@jamestrevorlees
jamestrevorlees / WordPress add_filter() example
Created June 30, 2016 16:06
WordPress add_filter() example and notes
function sample_function ( $content ) {
$content .= 'test';
return $content;
}
add_filter(
@jamestrevorlees
jamestrevorlees / WordPress add_action() example
Created June 30, 2016 17:59
WordPress add_action() example
//Actions are triggered by specific events that take place take place in WordPress eg. publishing a post
function sample_function () {
}
add_action('wp_head', 'sample_function'); /* we are hooking sample_function into the wp_head (an existing WP function) so that when wp_head fires then 'sample_function' is executed.
//we have parameters that are available to our functions depending on the actions that have been fired
@jamestrevorlees
jamestrevorlees / register_post_type() example
Created June 30, 2016 18:00
Pippin's plugins Register Post type example - WordPress
<?php
/*
Plugin Name: Plugin Development 101
Plugin URI: https://pippinsplugins.com/series/plugin-development-101/
Description: An introductory course on plugin development
Author: Pippin Williamson
Version: 1.0
Author URI: https://pippinsplugins.com
*/
@jamestrevorlees
jamestrevorlees / register_post_type() - WordPress
Created June 30, 2016 18:01
register_post_type() example - WordPress
// Create Post Type for the In Person Assessment Logging
function psgp_in_person_assessments_create_post_type() {
/* Set up the arguments for the post type. */
$args = array(
/**
* A short description of what your post type is. As far as I know, this isn't used anywhere
* in core WordPress. However, themes may choose to display this on post type archives.
@jamestrevorlees
jamestrevorlees / HTML, CSS and JS
Created September 17, 2016 09:28
How to create a youtube video iframe in a lightbox with the youtube API
#1.First create the button / CTA for the youtube video. eg.
<div>
<a href="https://www.youtube.com/embed/gUNSGk3SHhI" class="lightbox"><i class="fa fa-play fa-8 home-play-btn" aria-hidden="true" style="font-size: 4em"></i></a>
</div>
#ensure that the class "lightbox" is added.
#2.Add the following html at the base of the doc
<div id="youtubelightbox" class="parent">
<div class="centeredchild">
<div class="videowrapper">
@jamestrevorlees
jamestrevorlees / how-to-git-recache.txt
Last active October 9, 2016 09:07
Adding or removing files onto your .gitignore when you are already tracking
Often we have to add or remove files from a gitignore. In order to do so I choose to recache git and this is how I do it:
1. make your .gitignore changes
2. Recache git
cmd: git rm -r --cached .
--> this tells git to remove the cache for all your files that are currently being tracked
3. Add all the files to git again
@jamestrevorlees
jamestrevorlees / update-links-mysql-db-wordpress
Created October 11, 2016 09:20
SQL Query to update links from a migrated WordPress Database
@jamestrevorlees
jamestrevorlees / timber_repeaterloop_bullets.txt
Last active March 17, 2017 13:31
Loop through repeater field on timber and twig
<div class="col">
<ul>
{% set i = 1 %}
{% for item in post.get_field('home_what_band_bullets_section_a') %}
<li>{{ item.bullet_copy_text }}</li>
{% set i = i + 1 %}
{% endfor %}
</ul>
@jamestrevorlees
jamestrevorlees / country-shortcode.php
Created November 10, 2017 14:09 — forked from MatthewEppelsheimer/country-shortcode.php
WP Contact Form 7 shortcode with list of Countries
<?php
/*
UPDATED: December 31, 2011.
Modifications:
- Truncated the longest country names, including:
-- British Indian Ocean Territories (Chagos Archipelago) -> British Indian Ocean Territories
-- South Georgia and the South Sandhich Islands -> South Georgia & S. Sandwich Islands