Skip to content

Instantly share code, notes, and snippets.

View mor10's full-sized avatar

Morten Rand-Hendriksen mor10

View GitHub Profile
@mor10
mor10 / advanced-featured-image.php
Last active August 29, 2015 14:01
Advanced responsive featured image function utilizing transients for caching.
Verifying that +mor10 is my openname (Bitcoin username). https://onename.com/mor10
@mor10
mor10 / wpcampus-functionality.php
Created July 12, 2016 21:58
Create plugin to introduce custom Lectures post type
<?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 / functions.php
Created July 12, 2016 23:08
Display custom taxonomies in taxonomy lists in Twenty Sixteen child theme
<?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 July 12, 2016 23:10
Change the default size of the Site Logo in a Twenty Sixteen child theme
<?php
function twentysixteen_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Twenty Sixteen, use a find and replace
* to change 'twentysixteen' to the name of your theme in all the template files
*/
load_theme_textdomain( 'wpcampus', get_template_directory() . '/languages' );
@mor10
mor10 / content-single.php
Created July 13, 2016 23:10
Generate automatic oEmbed from URL with Advanced Custom Field
<?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 / wpcampus-functionality.php
Created July 14, 2016 18:12
Create a basic WordPress plugin
<?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 / wpcampus-functionality.php
Created July 14, 2016 18:53
Add custom post type to index and search results
<?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 / functions.php
Last active January 25, 2017 23:08
Print Twenty Sixteen meta content in custom post type posts through child theme
<?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 / style.css
Last active January 22, 2018 04:53
WordPress child theme setup based on the Twenty Sixteen parent theme
/*
Theme Name: Twenty Sixteen Child Theme
Theme URI: https://2016.wpcampus.org/schedule/wordpress-masterclass/
Description: A Twenty Sixteen child theme
Author: Morten Rand-Hendriksen
Author URI: https://lynda.com/mor10
Template: twentysixteen
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html