Skip to content

Instantly share code, notes, and snippets.

View stephenbelyea's full-sized avatar
🤟

Stephen Belyea stephenbelyea

🤟
View GitHub Profile
@stephenbelyea
stephenbelyea / wp-config-local.php
Last active August 20, 2019 18:54
Pantheon WP Config Local
<?php
// Drop wp-config-local.php into local site's root dir.
// Get connection info from Pantheon project.
define('DB_NAME', '');
define('DB_USER', '');
define('DB_PASSWORD', '');
// Use HOST:PORT from Pantheon.
define('DB_HOST', '');
@stephenbelyea
stephenbelyea / functions.php
Created November 16, 2015 14:44
WP Theme Directory Shortcode
// Drop this in theme's functions.php file.
// Use shortcode [path_theme] from visual editor.
function custom_shortcode_path_theme( $atts ){
return get_stylesheet_directory_uri();
}
add_shortcode( 'path_theme', 'custom_shortcode_path_theme' );
@stephenbelyea
stephenbelyea / app.js
Last active December 22, 2015 22:20
Google Language Translator Accessibility Fixes
// Accessibility fixes for WordPress Google Language Translator plugin.
// Found on WP repo here: https://wordpress.org/plugins/google-language-translator/
// Wait for jQuery to be ready...
// Grab and test for main wrap inserted before script runs.
var glt = document.getElementById('google_language_translator');
if ( $(glt).length ) {
// Allow time for plugin to render.
setTimeout( function (){
@stephenbelyea
stephenbelyea / app.js
Last active February 22, 2016 01:23
Responsive YouTube Iframe
// Add a wrapper to any YouTube video. Depends on jQuery.
if ( $('iframe[src*="youtube."]').length ) {
$('iframe[src*="youtube."]').each( function () {
// Use the video's specified width as a max so we don't stretch.
var width = $(this).attr('width');
$(this).wrap('<div class="video-wrap" style="max-width:'+width+'px;"><div class="inner"></div></div>');
});
}
@stephenbelyea
stephenbelyea / functions.php
Created January 13, 2016 16:31
WordPress Fix ShortCode Breaks
// Fix WP shortcode breaks.
function wpex_fix_shortcodes($content){
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
$content = strtr($content, $array);
return $content;
}
@stephenbelyea
stephenbelyea / functions.php
Created January 14, 2016 14:58
Enable MCE Format Tool in WP
// Add format dropdown for MCE.
add_filter( 'mce_buttons_2', 'my_mce_editor_buttons' );
function my_mce_editor_buttons( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
// Add SMALL and LEAD (from Bootstrap) text options.
add_filter( 'tiny_mce_before_init', 'my_mce_before_init' );
function my_mce_before_init( $settings ) {
$style_formats = array(
@stephenbelyea
stephenbelyea / index.html
Created February 22, 2016 01:22
GA Local Dev Workaround
<script>
// If running on localhost, don't bother with GA init.
if ( document.location.hostname !== "localhost" ) {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', 'your-site.com');
ga('send', 'pageview');
}
@stephenbelyea
stephenbelyea / app.js
Created March 2, 2016 02:08
Set equal height items in a row.
var setEqualRows = function(){
$('[data-equal-row]').each(function(){
var items = $(this).find('[data-equal-item]'),
maxHeight = 0;
items.css('min-height','auto');
setTimeout(function(){
items.each(function(){
var thisHeight = $(this).outerHeight();
console.log(thisHeight);
maxHeight = (thisHeight > maxHeight)? thisHeight : maxHeight;
@stephenbelyea
stephenbelyea / app.js
Created March 3, 2016 02:11
Clickable CTAs with sensible link content.
// Manage click/focus states for CTA with inner link.
var setWrapCTAs = function (event) {
var wrap = $('[data-cta-wrap]'),
link = wrap.find('[data-cta-link]');
// Clicking on CTA wrapper triggers internal link.
wrap.on('click', function(e) {
e.preventDefault();
var path = $(this).find('[data-cta-link]').attr('href');
if ( path !== "" ) {
window.location = path;
@stephenbelyea
stephenbelyea / functions.php
Last active June 1, 2016 20:38
Add MCE shortcode button for WP content editor.
// Register the shortcode.
function my_custom_shortcode( $atts ) {
extract( shortcode_atts(
array(
'arg1' => '',
'arg2' => ''
), $atts )
);
$output = "Whatever you need your shortcode to do...";
return $output;