Skip to content

Instantly share code, notes, and snippets.

View itsdavidmorgan's full-sized avatar

David Morgan itsdavidmorgan

View GitHub Profile
@itsdavidmorgan
itsdavidmorgan / gist:5267891
Created March 29, 2013 00:23
Filters wp_title for printing
/*-----------------------------------------------------------------------------------------------------//
Filters wp_title to print a neat <title> tag based on what is being viewed.
/*-----------------------------------------------------------------------------------------------------*/
function organic_wp_title( $title, $sep ) {
global $page, $paged;
if ( is_feed() )
return $title;
@itsdavidmorgan
itsdavidmorgan / gist:5267896
Created March 29, 2013 00:24
Localized comments function
/*-----------------------------------------------------------------------------------------------------//
Comments Function
-------------------------------------------------------------------------------------------------------*/
if ( ! function_exists( 'organicthemes_comment' ) ) :
function organicthemes_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
@itsdavidmorgan
itsdavidmorgan / gist:5538285
Created May 8, 2013 04:56
Content width with active sidebars
function photographer_content_width() {
if ( ! is_single() || is_active_sidebar( 'post-sidebar' ) ) {
global $content_width;
$content_width = 900;
}
if ( ! is_home() || is_archive() || is_active_sidebar( 'blog-sidebar' ) ) {
global $content_width;
$content_width = 900;
}
if ( ! is_page() || is_active_sidebar( 'page-sidebar' ) ) {
/*
* Enable selective refresh for widgets.
*/
add_theme_support( 'customize-selective-refresh-widgets' );
@itsdavidmorgan
itsdavidmorgan / editor-assets.php
Last active January 8, 2018 21:42
Enqueue Editor Assets For Custom Block
<?php
function organic_profile_block_editor_assets() {
// Scripts.
wp_enqueue_script(
'organic-profile-block', // Handle.
plugins_url( 'block.js', __FILE__ ), // Block.js: We register the block here.
array( 'wp-blocks', 'wp-i18n', 'wp-element' ), // Dependencies, defined above.
filemtime( plugin_dir_path( __FILE__ ) . 'block.js' ) // filemtime — Gets file modification time.
);
@itsdavidmorgan
itsdavidmorgan / front-end-assets.php
Last active January 8, 2018 21:41
Enqueue Front-End Styles For Custom Block
<?php
function organic_profile_block_block_assets() {
// Styles.
wp_enqueue_style(
'organic-profile-block-frontend', // Handle.
plugins_url( 'style.css', __FILE__ ), // Block frontend CSS.
array( 'wp-blocks' ), // Dependency to include the CSS after it.
filemtime( plugin_dir_path( __FILE__ ) . 'style.css' ) // filemtime — Gets file modification time.
);
wp_enqueue_style(
@itsdavidmorgan
itsdavidmorgan / blockWrapper.js
Last active March 26, 2019 20:57
Wrapper Function For Custom Block
(function (blocks, editor, components, i18n, element) {
// Our custom block code.
})(
window.wp.blocks,
window.wp.editor,
window.wp.components,
window.wp.i18n,
window.wp.element
@itsdavidmorgan
itsdavidmorgan / blockComponents.js
Last active November 12, 2018 18:23
Import Block Components
(function (blocks, editor, components, i18n, element) {
var el = wp.element.createElement
var registerBlockType = wp.blocks.registerBlockType
var RichText = wp.editor.RichText
var BlockControls = wp.editor.BlockControls
var AlignmentToolbar = wp.editor.AlignmentToolbar
var MediaUpload = wp.editor.MediaUpload
var InspectorControls = wp.editor.InspectorControls
var TextControl = components.TextControl
@itsdavidmorgan
itsdavidmorgan / registerBlock.js
Last active November 12, 2018 18:18
Register Profile Block For Gutenberg
registerBlockType('organic/profile-block', { // The name of our block. Must be a string with prefix. Example: my-plugin/my-custom-block.
title: i18n.__('Profile'), // The title of our block.
description: i18n.__('A custom block for displaying personal profiles.'), // The description of our block.
icon: 'businessman', // Dashicon icon for our block. Custom icons can be added using inline SVGs.
category: 'common', // The category of the block.
attributes: { // Necessary for saving block content.
title: {
type: 'array',
source: 'children',
selector: 'h3'
@itsdavidmorgan
itsdavidmorgan / editVariables.js
Last active November 12, 2018 18:25
Variables For Edit Function Of Custom Profile Block
edit: function (props) {
var attributes = props.attributes
var alignment = props.attributes.alignment
var facebookURL = props.attributes.facebookURL
var twitterURL = props.attributes.twitterURL
var instagramURL = props.attributes.instagramURL
var linkedURL = props.attributes.linkedURL
var emailAddress = props.attributes.emailAddress
var onSelectImage = function (media) {