Actions allow you to detect when certain actions are performed, while hooks allow to modify the output of the slider.
The information in this chapter is for developers that are familiar with PHP and the WordPress API.
1. Actions
sliderpro_enqueue_scripts
Called when the slider's JavaScript files are enqueued. You can use this action to enqueue your own JavaScript files.
add_action( 'sliderpro_enqueue_scripts', 'add_my_scripts' ); function add_my_scripts() { wp_enqueue_script( 'my-script', 'path/to/script.js' ); }
sliderpro_enqueue_styles
Called when the slider's CSS files are enqueued. You can use this action to enqueue your own CSS files.
add_action( 'sliderpro_enqueue_styles', 'add_my_styles' ); function add_my_styles() { wp_enqueue_script( 'my-style', 'path/to/style.css' ); }
2. Filters
Note: The sliders are cached by default, so applying filters will not have an immediate effect, until the cache is cleared. However, you can disable the caching while testing in order to see your changes immediately. To do this, you need to add the allow_cache="false" attribute to the shortcode: [sliderpro id="3" allow_cache="false"].
sliderpro_default_settings
It allows you to modify the default slider settings.
add_filter( 'sliderpro_default_settings', 'change_default_settings' ); function change_default_settings( $settings ) { $settings['visible_size']['default_value'] = '70%'; return $settings; }
sliderpro_default_slide_settings
It allows you to modify the default slide settings.
add_filter( 'sliderpro_default_slide_settings', 'change_default_slide_settings' ); function change_default_slide_settings( $settings ) { $settings['posts_operator']['default_value'] = 'NOT IN'; return $settings; }
sliderpro_default_layer_settings
It allows you to modify the default layer settings.
add_filter( 'sliderpro_default_layer_settings', 'change_default_layer_settings' ); function change_default_layer_settings( $settings ) { $settings['preset_styles']['default_value'] = array( 'sp-white', 'sp-padding', 'sp-rounded' ); return $settings; }
sliderpro_posts_query_args
It allows you to modify the parameters passed to the WP_Query call when Posts slides are created.
add_filter( 'sliderpro_posts_query_args', 'custom_query', 10, 3 ); function custom_query( $query_args, $slider_id, $slide_index ) { if ( $slider_id === 3 && $slide_index === 1 ) { $query_args['order'] = 'DESC'; } return $query_args; }
sliderpro_posts_tags
It allows you to add custom tags to Posts slides.
add_filter( 'sliderpro_posts_tags', 'add_author_tag' ); // add the 'author' tag to the list of supported tags function add_author_tag( $tags ) { // associate the 'author' tag with the function that will render the tag $tags['author'] = 'render_author_tag'; return $tags; } // return the actual post author for the 'author' tag function render_author_tag( $tag_arg, $post ) { return $post->post_author; }
Please note that when you use a tag in the slider, you need to append the sp_ term, like this:[sp_author] .
You can also add an argument to the tag, like [sp_author.first] , and use that argument in the rendering function:
function render_author_tag( $tag_arg, $post ) { $result = $post->post_author; // if the 'first' argument is present, return only the first name if ( $tag_arg !== false && $tag_arg === 'first' ) { $name = explode( $result, ' ' ); $result = $name[0]; } return $result; }
sliderpro_gallery_tags
It allows you to add custom tags to Gallery slides.
add_filter( 'sliderpro_gallery_tags', 'add_image_id_tag' ); // add the 'image_id' tag to the list of supported tags function add_image_id_tag( $tags ) { // associate the 'image_id' tag with the function that will render the tag $tags['image_id'] = 'render_image_id'; return $tags; } // return the actual image ID for the 'image_id' tag function render_image_id( $tag_arg, $image ) { return $image->ID; }
Please note that when you use a tag in the slider, you need to append the sp_ term, like this:[sp_image_id] .
You can also add an argument to the tag, like [sp_image_id.my_arg] , and use that argument in the rendering function:
function render_image_id( $tag_arg, $image ) { $result = $image->ID; // if the 'my_arg' argument is present, do something if ( $tag_arg !== false && $tag_arg === 'my_arg' ) { // do something } return $result; }
sliderpro_flickr_tags
It allows you to add custom tags to Flickr slides.
add_filter( 'sliderpro_flickr_tags', 'add_photo_id_tag' ); // add the 'photo_id' tag to the list of supported tags function add_photo_id_tag( $tags ) { // associate the 'photo_id' tag with the function that will render the tag $tags['photo_id'] = 'render_photo_id'; return $tags; } // return the actual photo ID for the 'photo_id' tag function render_photo_id( $tag_arg, $photo ) { return $photo['id']; }
Please note that when you use a tag in the slider, you need to append the as_ term, like this:[sp_photo_id] .
You can also add an argument to the tag, like [sp_photo_id.my_arg] , and use that argument in the rendering function:
function render_photo_id( $tag_arg, $photo ) { $result = $photo['id']; // if the 'my_arg' argument is present, do something if ( $tag_arg !== false && $tag_arg === 'my_arg' ) { // do something } return $result; }
sliderpro_data
It allows you to modify the slider's set data, before the slider's output is generated based on that data.
add_filter( 'sliderpro_data', 'change_slide_content_type', 10, 2 ); function change_slide_content_type( $data, $slider_id ) { if ( $slider_id === 2 ) { $data['slides'][0]['settings']['content_type'] = 'posts'; } return $data; }
sliderpro_javascript
It allows you to append or prepend inline JavaScript code.
add_filter( 'sliderpro_javascript', 'add_javascript' ); function add_javascript( $js_code ) { $js_code .= '<script>alert('Hello World!');</script>'; return $js_code; }
sliderpro_classes
It allows you to add custom classes to the slider.
add_filter( 'sliderpro_classes', 'add_custom_slider_class', 10, 2 ); function add_custom_class( $classes, $slider_id ) { if ( $slider_id === 2 ) { $classes .= ' ' . 'my-custom-class'; } return $classes; }
sliderpro_slide_classes
It allows you to add custom classes to the slides.
add_filter( 'sliderpro_slide_classes', 'add_custom_slide_class', 10, 3 ); function add_custom_slide_class( $classes, $slider_id, $slide_index ) { if ( $slider_id === 1 && $slide_index === 2 ) { $classes .= ' ' . 'my-custom-class'; } return $classes; }
sliderpro_main_image_classes
It allows you to add custom classes to the background image.
add_filter( 'sliderpro_main_image_classes', 'add_main_image_class', 10, 3 ); function add_main_image_class( $classes, $slider_id, $slide_index ) { $classes .= ' sp-custom-bg-class'; return $classes; }
sliderpro_layer_classes
It allows you to add custom classes to the layers.
add_filter( 'sliderpro_layer_classes', 'add_custom_layer_class', 10, 3 ); function add_custom_layer_class( $classes, $slider_id, $slide_index ) { if ( $slider_id === 1 && $slide_index === 2 ) { $classes .= ' ' . 'my-custom-class'; } return $classes; }
sliderpro_thumbnail_classes
It allows you to add custom classes to the thumbnails.
add_filter( 'sliderpro_thumbnail_classes', 'add_custom_thumbnail_class', 10, 3 ); function add_custom_thumbnail_class( $classes, $slider_id, $slide_index ) { if ( $slider_id === 1 && $slide_index === 2 ) { $classes .= ' ' . 'my-custom-class'; } return $classes; }
sliderpro_caption_classes
It allows you to add custom classes to the caption.
add_filter( 'sliderpro_caption_classes', 'add_custom_caption_class', 10, 3 ); function add_custom_caption_class( $classes, $slider_id, $slide_index ) { if ( $slider_id === 1 && $slide_index === 2 ) { $classes .= ' ' . 'my-custom-class'; } return $classes; }
sliderpro_markup
It allows you to modify the slider's HTML markup before it's printed.
add_filter( 'sliderpro_markup', 'slider_markup', 10, 2 ); function slider_markup( $html_markup, $slider_id ) { if ( $slider_id === 3 ) { $html_markup .= '<div class="extra-element">some content</div>'; } return $html_markup; }
sliderpro_slide_markup
It allows you to modify the slide's HTML markup before it's printed.
add_filter( 'sliderpro_slide_markup', 'slider_slide_markup', 10, 3 ); function slider_slide_markup( $html_markup, $slider_id, $slide_index ) { $html_markup .= '<div class="extra-element">some content</div>'; return $html_markup; }
sliderpro_layer_markup
It allows you to modify the layer's HTML markup before it's printed.
add_filter( 'sliderpro_layer_markup', 'slider_layer_markup', 10, 3 ); function slider_layer_markup( $html_markup, $slider_id, $slide_index ) { $html_markup .= '<div class="extra-element">some content</div>'; return $html_markup; }
sliderpro_slide_link_classes
It allows you to add custom classes to the slide's link.
add_filter( 'sliderpro_slide_link_classes', 'add_slide_link_class', 10, 3 ); function add_slide_link_class( $classes, $slider_id, $slide_index ) { $classes .= ' sp-custom-link-class'; return $classes; }
sliderpro_slide_link_url
It allows you to modify the URL of the slide's link.
add_filter( 'sliderpro_slide_link_url', 'change_url', 10, 3 ); function change_url( $link_url, $slider_id, $slide_index ) { $link_url = str_replace( '/en/', '/de/', $link_url ); return $link_url; }
sliderpro_thumbnail_link_classes
It allows you to add custom classes to the thumbnail's link.
add_filter( 'sliderpro_thumbnail_link_classes', 'add_thumbnail_link_class', 10, 3 ); function add_slide_link_class( $classes, $slider_id, $slide_index ) { $classes .= ' sp-custom-link-class'; return $classes; }
sliderpro_thumbnail_link_url
It allows you to modify the URL of the thumbnail's link.
add_filter( 'sliderpro_thumbnail_link_url', 'change_url', 10, 3 ); function change_url( $link_url, $slider_id, $slide_index ) { $link_url = str_replace( '/en/', '/de/', $link_url ); return $link_url; }
sliderpro_layer_content
Called when the layer's inner text (in the case of paragraph or heading layers) or inner HTML (in the case of DIV or video layers) is printed. It allows you to modify the content of the layer.
add_filter( 'sliderpro_layer_content', 'change_layer_content', 10, 3 ); function change_layer_content( $content, $slider_id, $slide_index ) { $content = '<strong>' . $content . '</strong>'; return $content; }
sliderpro_layer_image_link_url
It allows you to modify the URL of the link specified for an image layer.
add_filter( 'sliderpro_layer_image_link_url', 'change_image_url', 10, 3 ); function change_image_url( $link_url, $slider_id, $slide_index ) { $link_url = str_replace( '/en/', '/de/', $link_url ); return $link_url; }
sliderpro_slide_html
It allows you to modify the slide's inline HTML content before it's printed. Please note that this is different from sliderpro_slide_markup , which returns the entire HTML markup of the slide, not only the inline HTML content.
add_filter( 'sliderpro_slide_html', 'slide_html', 10, 3 ); function slide_html( $inline_html, $slider_id, $slide_index ) { $inline_html = '<div class="wrapper">' . $inline_html . '</div>'; return $inline_html; }
sliderpro_slide_caption
It allows you to modify the slide's caption content before it's printed.
add_filter( 'sliderpro_slide_caption', 'slide_caption', 10, 3 ); function slide_caption( $caption, $slider_id, $slide_index ) { $caption = '<div class="wrapper">' . $caption . '</div>'; return $caption; }
sliderpro_restricted_pages
It allows you to hide the plugin's admin pages. For example, you could hide the 'Plugins Settings' page from 'Editors'.
add_filter( 'sliderpro_restricted_pages', 'restricted_pages' ); function restricted_pages( $restricted_pages ) { $restricted_pages[] = 'sliderpro-settings'; $restricted_pages[] = 'sliderpro-custom'; return $restricted_pages; }
0 Comments