Skip to content

Instantly share code, notes, and snippets.

@besimhu
besimhu / Pull content from another page.php
Created March 15, 2015 16:03
Say you want to pull content from one page to a template or another page. Well this function is for you! You can also change get_page_by_path to get_page_by_id and utilize an id instead.
// Pull content from another page
function show_post($path) {
$post = get_page_by_path($path);
$content = apply_filters('the_content', $post->post_content);
echo $content;
}
// To use
<?php show_post('about'); ?>
@besimhu
besimhu / Make <iframe> videos responsive.php
Created March 15, 2015 16:02
To make videos responsive, mostly anything with <iframe> use the below function, and don’t forget to add the css as well.
// Add responsive container to embed videos
function forty_responsive_video( $html ) {
//add http protocol
$html = str_replace('<iframe src="//', '<iframe src="http://', $html);
return '<div class="flex-video">' . $html . '</div>';
}
add_filter( 'embed_oembed_html', 'forty_responsive_video', 10, 3 );
add_filter( 'video_embed_html', 'forty_responsive_video' );
@besimhu
besimhu / Add custom colors to TinyMCE.php
Created March 15, 2015 16:00
You can add custom colors to the TINYMCE editor, and this is especially handy if you want clients to stick to their color palette. Please be aware that this function gets rid of all colors and just adds in your selection.
// TINYMCE Options
function my_mce4_options( $init ) {
$custom_colours = '
"db1e34", "Color Name", "222c64", "Color Name Two"
';
$init['textcolor_map'] = '['.$custom_colours.']';
$init['textcolor_rows'] = 6;
return $init;
}
add_filter('tiny_mce_before_init', 'my_mce4_options');
@besimhu
besimhu / Add custom ACF option pages.php
Created March 15, 2015 15:59
Add custom ACF option pages for ACF 5
// Add custom ACF option pages
if(function_exists('acf_add_options_page')) {
acf_add_options_page();
acf_add_options_sub_page('Site Options');
}
@besimhu
besimhu / Add custom selectors to Gravity Forms.php
Created March 15, 2015 15:58
Add custom selectors to Gravity Forms
// Add custom selectors to Gravity Forms
add_action("gform_field_css_class", "custom_class", 10, 3);
function custom_class($classes, $field, $form){
$classes .= " " . $field["type"];
return $classes;
}
@besimhu
besimhu / Move Gravity Forms jQuery calls to footer.php
Created March 15, 2015 15:57
Move Gravity Forms jQuery calls to footer
@besimhu
besimhu / Add <figure> and remove <p> tags from images..php
Created March 15, 2015 15:56
Remove paragraph tags around photos and instead add <figure> tag
// Remove paragraph tags around photos and instead add <figure> tag
function img_unautop($pee) {
$pee = preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '<figure class="post-img">$1</figure>', $pee);
return $pee;
}
add_filter( 'the_content', 'img_unautop', 30 );
@besimhu
besimhu / Add to Google and iCal.js
Last active August 29, 2015 14:17
Allow visitors to save/download events to their iCal or Google Calendar. The ical.php needs to go into your functions folder, and be pulled in. Included are sample styles, markup, ACF field option export, + variable pulling. Not all options will carry across to iCal.
module.exports = function() {
function sendInformation(){
var months = [
'01',
'02',
'03',
'04',
'05',
'06',
@besimhu
besimhu / Hide navigation on scroll + close navigation if clicked outside.js
Last active August 29, 2015 14:17
Toggle navigation, hide navigation on scroll, and close navigation if clicked outside of navigation.
module.exports = function() {
require('./setupMqSync')();
var $root = $('body'),
$header = $root.find('.main-header'),
$nav = $root.find('.nav-primary'),
$menu_toggle = $header.find('.menu-trigger'),
$active_class = 'nav-open',
prevent_default = function(e) {
@besimhu
besimhu / Open all external links in new window.js
Last active August 29, 2015 14:17
Open all external links in a new window.