Skip to content

Instantly share code, notes, and snippets.

Avatar

Morten Rand-Hendriksen mor10

View GitHub Profile
@mor10
mor10 / Related-Component.php
Last active Jul 23, 2019
Extend WP Rig to display related posts using the REST API
View Related-Component.php
@mor10
mor10 / Component.php
Created Jul 22, 2019
Add color palette option to Customizer in WP Rig theme
View Component.php
<?php
/**
* WP_Rig\WP_Rig\Customizer\Component class
*
* @package wp_rig
*/
namespace WP_Rig\WP_Rig\Customizer;
use WP_Rig\WP_Rig\Component_Interface;
@mor10
mor10 / leos-twisty-toy.ino
Created Feb 7, 2018
Arduino script for detecting three analog potentiometer inputs and output four LEDs: red, green, blue, and RGB
View leos-twisty-toy.ino
// Pin declarations
int potPinR= A0; // Declare potPinR to be analog pin A0
int potPinG= A1; // Declare potPinG to be analog pin A1
int potPinB= A2; // Declare potPinB to be analog pin A2
int LEDPinR= 9; // Declare LEDPinR to be arduino pin 9
int LEDPinG= 10; // Declare LEDPinR to be arduino pin 10
int LEDPinB= 11; // Declare LEDPinR to be arduino pin 11
// Variables
int readValueR; // Use to store value from red potentiometer
@mor10
mor10 / wpcampus-functionality.php
Created Jul 14, 2016
Add custom post type to index and search results
View wpcampus-functionality.php
<?php
/**
* Include Lecture post type in the main and search queries
*/
function wpcampuscpt_query_filter( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
if ( $query->is_search() || $query->is_home() ) {
$query->set('post_type', array( 'post', 'lecture' ) );
}
}
@mor10
mor10 / wpcampus-functionality.php
Created Jul 14, 2016
Create a basic WordPress plugin
View wpcampus-functionality.php
<?php
/*
Plugin Name: WPCampus Functionality
Plugin URI: https://2016.wpcampus.org/schedule/wordpress-masterclass/
Description: Adds custom post types and taxonomies
Version: 1.0.0
Author: Morten Rand-Hendriksen
Author URI: https://lynda.com/mor10
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@mor10
mor10 / content-single.php
Created Jul 13, 2016
Generate automatic oEmbed from URL with Advanced Custom Field
View content-single.php
<?php
// Make sure the plugin is active
if ( function_exists( 'get_field' ) ) {
$lecture_video = get_field('lecture_video');
}
// If the current post is a Lecture post and we have a lecture video URL, use oEmbed
if ( 'lecture' === get_post_type() ) {
if ( $lecture_video ) {
echo wp_oembed_get( $lecture_video );
}
@mor10
mor10 / functions.php
Created Jul 12, 2016
Display custom taxonomies in taxonomy lists in Twenty Sixteen child theme
View functions.php
<?php
/**
* Prints HTML with category and tags for current post.
* Augmented from the Twenty Sixteen original, found in inc/template-tags.php
*/
function twentysixteen_entry_taxonomies() {
// Display Class taxonomy when available
$tax_class_title = '<span class="tax-title">' . __( 'Class:', 'wpcampus' ) . '</span> ';
$class_list = get_the_term_list( $post->ID, 'class', $tax_class_title, _x( ', ', 'Used between list items, there is a space after the comma.', 'wpcampus' ) );
@mor10
mor10 / functions.php
Last active Jan 25, 2017
Print Twenty Sixteen meta content in custom post type posts through child theme
View functions.php
<?php
/**
* Prints HTML with meta information for the categories, tags, etc.
* Augmented from the Twenty Sixteen original, found in inc/template-tags.php
*/
function twentysixteen_entry_meta() {
if ( 'post' === get_post_type() || 'lecture' === get_post_type() ) {
$author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 );
printf( '<span class="byline"><span class="author vcard">%1$s<span class="screen-reader-text">%2$s </span> <a class="url fn n" href="%3$s">%4$s</a></span></span>',
get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ),
@mor10
mor10 / wpcampus-functionality.php
Created Jul 12, 2016
Create custom taxonomies (hierarchical and non-hierarchical) in a WordPress plugin
View wpcampus-functionality.php
<?php
// Create two taxonomies, Class and Year, for the post type "Lecture"
function wpcampuscpt_lecture_taxonomies() {
// Add Class taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Classs', 'taxonomy general name' ),
'singular_name' => _x( 'Class', 'taxonomy singular name' ),
'search_items' => __( 'Search Classes' ),
'all_items' => __( 'All Classes' ),
'parent_item' => __( 'Parent Class' ),
@mor10
mor10 / wpcampus-functionality.php
Created Jul 12, 2016
Create plugin to introduce custom Lectures post type
View wpcampus-functionality.php
<?php
/*
Plugin Name: WPCampus Functionality
Plugin URI: https://2016.wpcampus.org/schedule/wordpress-masterclass/
Description: Adds custom post types and taxonomies
Version: 1.0.0
Author: Morten Rand-Hendriksen
Author URI: https://lynda.com/mor10
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html