Skip to content

Instantly share code, notes, and snippets.

@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 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 / 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 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 / 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 / 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 / Remove jump from <-more-> tag.php
Last active August 29, 2015 14:17
Sometimes you want to use the <-more-> tag to link to the full post. That being said, the only problem with that is that it jumps to the part where the tag was added. Here a function that removes the jump.
// Remove jump with <-more-> tag
function remove_more_jump_link($link) {
$offset = strpos($link, '#more-');
if ($offset) { $end = strpos($link, '"',$offset); }
if ($end) { $link = substr_replace($link, '', $offset, $end-$offset); }
return $link;
}
add_filter('the_content_more_link', 'remove_more_jump_link');
@besimhu
besimhu / Check if it’s part of the blog.php
Created March 15, 2015 16:05
Sometimes you just want to have one check that checks if it’s related to the blog. Yes, this uses many functions, so use it as a last resort.
// check if it's a blog page
function is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') );
}
@besimhu
besimhu / Show Custom Post Types in Tag Search.php
Created March 15, 2015 16:06
When you view a tag, it only lists custom post type with ‘post’ … this function changes that.
// Allow custom post types in tag search
function post_type_tags_fix($request) {
if ( isset($request['tag']) && !isset($request['post_type']) )
$request['post_type'] = 'any';
return $request;
}
add_filter('request', 'post_type_tags_fix');
@besimhu
besimhu / Remove Admin Bar Margin.php
Created March 15, 2015 16:06
Sometimes if you have a site with a lot of fixed elements, the admin bar sure can be a pain. This removes the margin that gets added.
// Remove Admin Bar Margin
add_action('get_header', 'my_filter_head');
function my_filter_head() {
remove_action('wp_head', '_admin_bar_bump_cb');
}