Skip to content

Instantly share code, notes, and snippets.

@joemcgill
joemcgill / better_wp_images.php
Last active October 14, 2016 08:11
A set of function to improve the markup of images inserted into the editor in Wordpress.
<?php
function show_img_vars($html, $id, $caption, $title, $align, $url, $size, $alt) {
// remove alignment class from the image
$html = preg_replace( '/ class=".*"/', '', $html );
// return the normal html output you would expect
$figure = "<figure class='image-inline";
if ($align == 'left' | 'right') {
$figure .= " align".$align;
@joemcgill
joemcgill / show_img_vars.php
Last active October 14, 2016 08:11
A poor man's var_dump for the image_send_to_editor() filter in Wordpress. Throw this in your functions.php file and add an image to your post to see what get's passed. Filter it however you want to return the image however you want.
<?php
function show_img_vars($html, $id, $caption, $title, $align, $url, $size, $alt) {
// round up all the variables that get passed so we can test them
$vars = "html = $html\n";
$vars .= "id = $id\n";
$vars .= "caption = $caption\n";
$vars .= "title = $title\n"; // this will end up blank no matter what
$vars .= "align = $align\n";
$vars .= "url = $url\n";
@joemcgill
joemcgill / Customize TinyMCE in WP
Last active October 14, 2016 08:11
Set of functions for easily customizing the tinyMCE editor in WordPress. More references: Wes Bos – http://wesbos.com/custom-wordpress-tinymce-wysiwyg-classes/ TinyMCE Reference – http://www.tinymce.com/wiki.php/TinyMCE3x:Buttons/controls
// add style selector drop down
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
// customize the MCE editor
function my_customize_mce( $init ) {
@joemcgill
joemcgill / parse_youtube_url
Created September 16, 2013 20:30
A handy javascript function for parsing YouTube urls and returning just the video URI (adapted from: http://stackoverflow.com/posts/9102270/revisions).
function parse_youtube_url(url) {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=v=|\&v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match&&match[2].length==11){
return match[2];
}else{
//error
}
}
@joemcgill
joemcgill / WP Fix Image Margins
Last active October 14, 2016 08:11
Removes the silly 10px margin from caption based images in WP (H/T Justin Adie)
/**
* Description: removes the silly 10px margin from caption based images
* Author: Justin Adie
* Version: 0.1.0
* Author URI: http://rathercurious.net
*/
class fixImageMargins{
public $xs = 0; //change this to change the amount of extra spacing
@joemcgill
joemcgill / wp_kill_parent_post
Created November 17, 2013 05:51
Remove a custom post type from a parent theme in WordPress.
add_action('after_setup_theme', 'wp_kill_parent_post');
function wp_kill_parent_post() {
remove_action('init', '<% parent post name %>');
}
// Register your own version in place of the parent post type if you want
@joemcgill
joemcgill / wp_css_tricks_images_responsive.php
Created December 28, 2015 04:36
CSS Tricks Responsive Image Filter
function wp_css_tricks_images_responsive( $content ) {
/**
* Find all instanced of your custom image markup in the content and bail early
* if none are found.
*/
if ( ! preg_match_all( '/<figure [^>]+>\s+<img [^>]+>/', $content, $matches ) ) {
return $content;
}
// Set up arrays to hold your images and a set of IDs that we'll cache later.
@joemcgill
joemcgill / Bootstrapped Contact Forms 7
Last active May 16, 2016 14:02
Boilerplate form code for the WP Contact Forms 7 plugin that makes use of Bootstrap styles
<div class="form-group">
<label for="your-name">My Name</label>[text your-name class:form-control]
</div>
<div class="form-group">
<label for="your-email">Email Address</label>[email your-email class:form-control]
</div>
<div class="form-group">
<label for="your-message">Your Message</label>[textarea your-message class:form-control]
@joemcgill
joemcgill / new-staff-setup.md
Last active February 4, 2016 19:53
New Developer Setup

Computer/Tooling

Much of the software that we use will be installed by Jeff/Galen on your new computer. This includes MS Office, Adobe Creative Suite, Etc. This is a list of things you will need to install yourself.

@joemcgill
joemcgill / WP_Image.md
Last active January 29, 2016 19:11
Ideas for a WP_Image Class in WordPress

Goals

  • Mimic the properties of WP_Post, and include additional metadata that's stored for images
    • _wp_attached_file
    • _wp_attachement_metadata
    • _wp_attachment_is_custom_background (maybe?)
  • Include methods for retrieving data associated with an image, possibly replacing the wp_get_attachment_image_ family of functions.
  • Save any reused data that would be used across functions so it's not calculated multiple times (e.g., wp_upload_dir(), see: #34359).
  • Maintain backwards compatability with the media.php image functions.