Skip to content

Instantly share code, notes, and snippets.

@tomhemsley
tomhemsley / gist:32786e0fa7f01ad6db59
Created October 16, 2014 10:46
Add style.css to preview
function metaslider_add_style_to_preview() {
wp_enqueue_style( 'theme-css', get_template_directory_uri() . '/style.css', array(), '', true );
}
add_action( 'admin_post_metaslider_preview', 'metaslider_add_style_to_preview', 9 );
@tomhemsley
tomhemsley / gist:87270edaf6247352dfef
Last active August 29, 2015 14:07
Meta Slider - Pause on slide
/**
* INSTALLATION: this code should be pasted into your theme's functions.php file.
*/
function metaslider_pause_on_slide($options, $slider_id, $settings) {
$slide_to_pause = 3; // <- change this number
// do not edit below this line
$options['after'][] = "if (slider.currentSlide == ({$slide_to_pause} - 1)) { slider.pause(); }";
@tomhemsley
tomhemsley / gist:fe9ed89de1ff984b62e2
Created September 15, 2014 12:29
Custom Caption
function metaslider_custom_caption($slide, $slideshow_id) {
// populate the caption using other fields
$slide['caption'] = $slide['caption'] . $slide['title'] . $slide['alt'];
return $slide;
}
add_filter('metaslider_image_slide_attributes', 'metaslider_custom_caption',10, 2);
@tomhemsley
tomhemsley / gist:b8abecfbd4ced97801dd
Created September 12, 2014 13:44
Reset filmstrip loop
function metaslider_reset_filmstrip($options, $slider_id, $settings) {
$options['before'][] = "if (slider.currentSlide + 1 == slider.count) { $('#metaslider_{$slider_id}_filmstrip').flexslider(0); }" ;
return $options;
}
add_filter('metaslider_flex_slider_parameters', 'metaslider_reset_filmstrip', 10, 3);
@tomhemsley
tomhemsley / gist:f72318b9e576cb1c5235
Created September 9, 2014 11:50
Show slideshow ID above table
function ms_show_id($slider_id) {
echo "ID: " . $slider_id;
}
add_action('metaslider_admin_table_before', 'ms_show_id', 10, 1);
@tomhemsley
tomhemsley / gist:7f80d70da35cb1c3beb1
Created August 26, 2014 10:21
Meta Slider - Flex Slider Pause / Play button
function metaslider_flex_params($options, $slider_id) {
$options['pausePlay'] = "true"; // enable pause/play
$options['pauseText'] = "'Pause'";
$options['playText'] = "'Play'";
$options['controlsContainer'] = "'#metaslider_container_100'"; // change 100 to your slideshow ID
return $options;
}
add_filter('metaslider_flex_slider_parameters', 'metaslider_flex_params', 10, 2);
@tomhemsley
tomhemsley / gist:e01e2efb0e62e3b04705
Created August 19, 2014 13:59
Meta Slider Thumbnail Captions (Post Feed)
/**
* Installation:
*
* Copy and paste this code into your themes functions.php file.
*
* Create a new custom field for your posts (to do this, edit one of your posts in WordPress, click 'Screen options' at the top of * the page and enable 'custom fields'). Name the custom field 'metaslider_thumb_caption' and enter the text for the caption as
* the value
*
*/
@tomhemsley
tomhemsley / gist:6041d51dc480e21ddac9
Created August 14, 2014 10:11
Meta Slider by Slug
/**
* Filter the shortcode attributes.
* If the ID parameter is not an integer, assume it is a slug.
* Convert the slug to an ID and return the attributes.
*/
function metaslider_shortcode_slug( $atts ) {
if ( isset( $atts['id'] ) && ! is_int( $atts['id'] ) ) {
$slider = get_page_by_path( $atts['id'], OBJECT, 'ml-slider' );
@tomhemsley
tomhemsley / gist:e985db339da947fa035d
Created August 5, 2014 12:33
Meta Slider Change Capability / User Role Editor
/**
* The default capability required to use Meta Slider is 'edit_others_posts'.
* You can change this to a different capability by pasting the code below into
* your themes functions.php file.
*
* You can use the 'User Role Editor' plugin to add a custom capability to WordPress
* specifically for Meta Slider users.
*/
function metaslider_change_required_role($capability) {
return 'metaslider_use'; // this is the ID of a custom capability added using User Role Editor
@tomhemsley
tomhemsley / gist:60e94d5a29f34968bbd3
Created July 29, 2014 10:29
Meta Slider - WP Lightbox 2 Integration
/**
* INSTALLATION: this code should be pasted into your theme's functions.php file.
*
* To Use: Install 'WP Lightbox 2'. Leave the URL blank on an image slide in Meta Slider.
* The slide will automatically be linked to it's full image in a lightbox
*/
function metaslider_wp_lightbox_2($attributes, $slide, $slider_id) {
if (!strlen($attributes['href'])) {
$attributes['href'] = wp_get_attachment_url($slide['id']);
$attributes['rel'] = "lightbox[{$slider_id}]";