Skip to content

Instantly share code, notes, and snippets.

View mor10's full-sized avatar

Morten Rand-Hendriksen mor10

View GitHub Profile
@mor10
mor10 / my-responsive-thumbnail.php
Created May 28, 2014 01:46
Basic function to create responsive featured image in WordPress. Code to be added to functions.php.
<?php
/**
* Create function my_responsive_thumbnail() to output responsive featured image
* Function can be called from within the loop of any template file using my_responsive_thumbnail(get_the_ID());
*/
function my_responsive_thumbnail($post_id){
// Get the featured image ID
$attachment_id = get_post_thumbnail_id($post_id);
// Get the alt text or set the $alt_text variable to the post title if no alt text exists
@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 / 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
@mor10
mor10 / functions.php
Created July 11, 2016 20:14
Alternative method for adding parent theme stylesheet to WordPress child theme
<?php
// Enqueue the parent theme stylesheet, then the child theme stylesheet.
// Used in place of @import rule in child theme style.css
function child_theme_name_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style' ) );
}
add_action( 'wp_enqueue_scripts', 'child_theme_name_enqueue_styles' );
@mor10
mor10 / functions.php
Created July 11, 2016 21:04
Change default fonts in Twenty Sixteen Child Theme
<?php
// Override the parent theme fonts
function twentysixteen_fonts_url() {
$fonts_url = 'https://fonts.googleapis.com/css?family=Playfair+Display:400,400i,700,700i,900,900i|Roboto+Slab:400,700';
return $fonts_url;
}
?>
@mor10
mor10 / header.php
Last active October 16, 2019 10:53
Reposition header image and logo in Twenty Sixteen child theme
<?php
/**
* Custom header for the WPCampus child theme.
* Moves the header image to the top.
*
* The template for displaying the header
*
* Displays all of the head element and everything up until the "site-content" div.
*
* @package WordPress
@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 / functions.php
Created July 11, 2016 23:44
Custom page template with no sidebar for Twenty Sixteen child theme
<?php
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array (Maybe) filtered body classes.
*/
function wpcampus_body_classes( $classes ) {
// Adds a class of no-sidebar to custom no-sidebar page template.
if ( is_page_template('page-no-sidebar.php') ) {
@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