Skip to content

Instantly share code, notes, and snippets.

View mrwweb's full-sized avatar

Mark Root-Wiley mrwweb

View GitHub Profile
<?php
/*
Plugin Name: Google PDF Viewer Shortcode
Description: Display a PDF in the browser with Google's PDF viewer. Usage: [pdf]http://example.org/some-public-document.pdf[/pdf]. Can specify optional width and height attribrutes like this [pdf width="100" height="100"]http://example.org/a-very-tiny-document.pdf[/pdf]
Version: 1.0
Author: Mark Root-Wiley
Author URI: https://mrwweb.com
*/
/* a shortcode for embedding PDFs via Google Docs viewer */
function nten_pdf_shortcode( $atts, $content = '' ) {
@mrwweb
mrwweb / superclick-init-plus.js
Created December 16, 2016 22:46
Some nice little tweaks to the default superclick init
(function($){ //create closure so we can safely use $ as alias for jQuery
"use strict";
$(document).ready(function(){
var mainMenu = $('#primary-menu').superclick({
activeClass: 'sf-active', // change active class from sfHover to sf-active
cssArrows: false, // no arrows (but you should probably provide your own)
speed: 1, // "no animation"
onShow: function() {
// keep off screen momentarily
@mrwweb
mrwweb / empty-alt.php
Created December 16, 2016 20:48
Highlight images with empty alt for logged in editors
<?php
add_action( 'wp_head', 'mrw_highlight_empty_alt' );
function mrw_highlight_empty_alt() {
if( is_user_logged_in() ) : ?>
<style>
[alt=""] {
border: 10px solid red !important;
}
</style>
<?php
@mrwweb
mrwweb / functions.php
Last active March 18, 2023 04:58
Example Child Theme Files
<?php
/*
Important!
Make sure to replace {my_} with your theme's unique prefix.
All future functions you write should use that same prefix.
Example: mrwnten_parent_theme_enqueue_styles()
*/
add_action( 'wp_enqueue_scripts', '{my_}parent_theme_enqueue_styles' );
@mrwweb
mrwweb / fpw_excerpt-filter-example.php
Created November 15, 2016 21:42
Return page content instead of excerpt in all Feature a Page Widgets
<?php
add_filter( 'fpw_excerpt', 'fpw_replace_excerpt_with_content', 10, 2 );
function fpw_replace_excerpt_with_content( $excerpt, $id ) {
return get_post_field( 'post_content', $id );
}
@mrwweb
mrwweb / first_val_as_array_key.php
Created December 31, 2015 18:30
Given an array of array, make the first value of each array the array key.
<?php
function key_my_array( $array_array ) {
$new_array_array = array();
foreach( $array_array as $array ) {
$first = array_shift($array);
$new_array_array[$first] = $array;
}
return $new_array_array;
}
@mrwweb
mrwweb / first_val_as_array_key.php
Created December 31, 2015 18:30
Given an array of array, make the first value of each array the array key.
<?php
function key_my_array( $array_array ) {
$new_array_array = array();
foreach( $array_array as $array ) {
$first = array_shift($array);
$new_array_array[$first] = $array;
}
return $new_array_array;
}
@mrwweb
mrwweb / input.scss
Last active December 21, 2015 20:16
Example of using Breakpoint SASS library for media queries. (http://breakpoint-sass.com/)
/*================================================
* SCSS
================================================*/
/* Import Breakpoint */
@import "breakpoint";
/* Named Media Queries */
@include breakpoint-set( 'to ems', true );
$tiny: ('screen') 300px, 'no-query' true;
@mrwweb
mrwweb / prefixless_archive_titles.php
Created December 16, 2015 22:35
Simple category and other archive page titles in WordPress 4.1+
<?php
add_filter( 'get_the_archive_title', '{prefix}_cat_title' );
/**
* Remove "Category: " prefix from Category archive pages
*/
function {prefix}_cat_title( $title ) {
if( is_category() ) {
$title = single_cat_title( '', false );
}
@mrwweb
mrwweb / sticky_class_archives.php
Last active December 16, 2015 22:17
Add sticky class to posts in archives
<?php
function {prefix}_post_class( $classes ) {
if( is_archive() && is_sticky() ) {
$classes[] = 'sticky';
}
return $classes;
}
add_filter( 'post_class', '{prefix}_post_class' );