Switching Hover/Touch Events For Desktop/Mobile Devices
The following snippet will switch the classical desktop hover events to touch events.
1 2 3 4 5 6 7 8 9 10 11 |
var isTouchSupported = 'ontouchstart' in window; var startEvent = isTouchSupported ? 'touchstart' : 'mouseenter'; var endEvent = isTouchSupported ? 'touchend' : 'mouseleave'; $('.yourclass').on(startEvent,function(){ doSomething(this); }); $('.yourclass').on(endEvent,function(){ doSomething(this); }); |
Snippet Source/Credit: jbkflex.wordpress.com
How To Make Accessible Menu Editor
Adding the following snippet to your theme’s functions.php file, you will be able to make accessible menu editor.
1 2 |
$ Role_object = get_role ( 'editor' ) ; $ role_object -> add_cap ( 'edit_theme_options' ) ; |
Snippet Source/Credit: Webundso
How To Simulate A View Of A Page With JavaScript Onclick
Using the following snippet, you will be able to simulate a view of a page with JavaScript onclick.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<input id="submit" onclick="trackpage('/kontaktudfyldt/')" type="submit" value="<?php _e('Send Email', 'framework') ?>" /> <script type="text/javascript"> // <![CDATA[ var readytosubmit = false; function trackpage (track) { _gaq.push(['_trackPageview',track]); readytosubmit = !readytosubmit; setTimeout(clicksubmit(), 100)} function clicksubmit() { document.getElementById("submit").click(); } // ]]> </script> |
Snippet Source/Credit: Reiffs.dk
How To Add Rel=”Lightbox” To All Images Embedded In A Post
The use of following snippet will let you add rel=”lightbox” to all images embedded in a post.
1 2 3 4 5 6 7 8 |
add_filter('the_content', 'my_addlightboxrel'); function my_addlightboxrel($content) { global $post; $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i"; $replacement = '<a$1href=$2$3.$4$5 rel="lightbox" title="'.$post->post_title.'"$6>'; $content = preg_replace($pattern, $replacement, $content); return $content; } |
Snippet Source/Credit: Snipplr
How To Change The CSS In WordPress
Using the following snippet, you will be able to change the CSS in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
//deactivate WordPress function remove_shortcode('gallery', 'gallery_shortcode'); //activate own function add_shortcode('gallery', 'wpe_gallery_shortcode'); //the own renamed function function wpe_gallery_shortcode($attr) { global $post, $wp_locale; static $instance = 0; $instance++; // Allow plugins/themes to override the default gallery template. $output = apply_filters('post_gallery', '', $attr); if ( $output != '' ) return $output; // We're trusting author input, so let's at least make sure it looks like a valid orderby statement if ( isset( $attr['orderby'] ) ) { $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); if ( !$attr['orderby'] ) unset( $attr['orderby'] ); } extract(shortcode_atts(array( 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => '' ), $attr)); $id = intval($id); if ( 'RAND' == $order ) $orderby = 'none'; if ( !empty($include) ) { $include = preg_replace( '/[^0-9,]+/', '', $include ); $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); $attachments = array(); foreach ( $_attachments as $key => $val ) { $attachments[$val->ID] = $_attachments[$key]; } } elseif ( !empty($exclude) ) { $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); } else { $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); } if ( empty($attachments) ) return ''; if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $att_id => $attachment ) $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; return $output; } $itemtag = tag_escape($itemtag); $captiontag = tag_escape($captiontag); $columns = intval($columns); $itemwidth = $columns > 0 ? floor(100/$columns) : 100; $float = is_rtl() ? 'right' : 'left'; $selector = "gallery-{$instance}"; $gallery_style = $gallery_div = ''; if ( apply_filters( 'use_default_gallery_style', true ) ) $gallery_style = " <style type='text/css'> </style> <!-- see wpe_gallery_shortcode() in wp-includes/media.php -->"; $size_class = sanitize_html_class( $size ); $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>"; $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div ); $i = 0; foreach ( $attachments as $id => $attachment ) { $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); $output .= "<{$itemtag} class='gallery-item'>"; $output .= " <{$icontag} class='gallery-icon'> $link </{$icontag}>"; if ( $captiontag && trim($attachment->post_excerpt) ) { $output .= " <{$captiontag} class='wp-caption-text gallery-caption'> " . wptexturize($attachment->post_excerpt) . " </{$captiontag}>"; } $output .= "</{$itemtag}>"; if ( $columns > 0 && ++$i % $columns == 0 ) $output .= ''; } $output .= " </div>\n"; return $output; } |
Snippet Source/Credit: WPEngineer