Filter Hooks
The following core Ajax Load More filters are available to support the modification of query arguments and display settings.
- Query/Functional Filters
- alm_query_args_{id}
- alm_query_after_{id}
- alm_allow_future_posts
- alm_debug
- alm_disable_noscript_{id}
- alm_repeater_path
- Display Filters
- alm_after_container
- alm_before_button
- alm_before_container
- alm_button_label
- alm_button_wrap_classes
- alm_settings
- alm_shortcode_defaults
- alm_speed
- Admin Filters
- alm_mask_license_keys
Query Filters
alm_query_args_{id}
The alm_query_args_{id} filter can be used to modify WP_Query arguments by Ajax Load More instance ID.
The following snippet would be pasted in your theme’s functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function my_movie_listing( $args, $id ){ // ALM Shortcode // [ajax_load_more id="movie_listing" button_label="More Movies"] $args['post_type'] = 'movie'; $args['tax_query'] = array( array( 'taxonomy' => 'genre', 'field' => 'slug', 'terms' => 'comedy' ) ); return $args; } add_filter( 'alm_query_args_movie_listing', 'my_movie_listing', 10, 2); |
This filter requires the following 2 step process:
- Set Unique ID – Create a unique ID for your ALM instance by setting a value for the id parameter in the shortcode.
[ajax_load_more id="your_id"] - Add Filter – Create the custom filter and function for this instance by appending the unique ID to the filter name.
add_filter(‘alm_query_args_your_id’, ‘my_function_name’);
When is this filter useful?
This filter is useful for advanced users who prefer to write custom queries over working with shortcode parameters.
Note: Never modify the offset or paged query parameters – these parameters must be set within the core plugin or results may be undesired.
Parsing Querystrings
You can dynamically build a custom query by parsing a querystring URL directly inside the alm_query_args filter.
The following snippet retrieves a category value from a querystring and adds the category parameter to the $args array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// functions.php function my_alm_query_args( $args ){ // https://website.com/?category=design $url = $_SERVER["HTTP_REFERER"]; // Get referring URL. $parts = parse_url($url); // Parse the URL parse_str( $parts['query'], $querystring ); // Get the querystring. if( $querystring ){ if( $querystring['category'] ){ $args['category'] = $querystring['category']; // Add category to $args array. } } return $args; } add_filter( 'alm_query_args_default', 'my_alm_query_args' ); |
alm_query_after_{id}
The alm_query_after_{id} filter can be used to modify the results of a WP_Query by Ajax Load More instance ID.
1 2 3 4 5 6 7 8 9 |
// [ajax_load_more id="default"] function my_alm_query_after( $query ){ usort($query->posts, function( $a, $b ) { return strnatcasecmp( $a->post_name,$b->post_name ); }); return $query; } add_filter( 'alm_query_after_default', 'my_alm_query_after' ); |
alm_allow_future_posts
This filter is used to allow for future posts to be displayed for all users. By default, ALM does not allow for future posts to be displayed for non-admin users.
1 |
add_filter( 'alm_allow_future_posts', '__return_true' ); |
alm_debug
This filter is used to display the Ajax Load More WP_Query arguments in the browser console. Debug data will be returned in a unique entry labeled alm_debug in the browser console.
1 |
add_filter( 'alm_debug', '__return_true' ); |
alm_disable_noscript_{id}
The alm_disable_noscript_{id} filter can be used to remove the <noscript/> tags that are dynamically generated by the Filters and SEO add-ons.
1 2 |
// [ajax_load_more id="default"] add_filter( 'alm_disable_noscript_default', '__return_true' ) |
1 |
add_filter( 'alm_disable_noscript_', '__return_true' ) |
alm_repeater_path
The alm_repeater_path filter can be used to change the Repeater Template directory path. By default, Repeater Templates are saved in a alm_templates folder located in the wp-content/uploads directory.
1 2 3 4 |
// Update Repeater Template Directory. add_filter( 'alm_repeater_path', function(){ return get_stylesheet_directory() .'/my-alm-templates'; }); |
Display Options
alm_after_container
This filter is used to add content or HTML after the Ajax Load More container.
1 2 3 4 |
function my_custom_alm_after_container() { return '<p><a href="/work">View All Work</a></p>'; } add_filter( 'alm_after_container', 'my_custom_alm_after_container' ); |
alm_after_button
This filter is used to add content after the load more .alm-button-wrap button container.
1 2 3 4 |
function my_custom_alm_after_button() { return '<hr/>'; } add_filter( 'alm_after_button', 'my_custom_alm_after_button' ); |
alm_before_button
This filter is used to add content before the load more .alm-button-wrap button container.
1 2 3 4 |
function my_custom_alm_before_button() { return '<hr/>'; } add_filter( 'alm_before_button', 'my_custom_alm_before_button' ); |
alm_before_container
This filter is used to add content or HTML before the Ajax Load More container.
1 2 3 4 |
function my_custom_alm_before_container() { return '<h2>Our Recent Work!</h2>'; } add_filter( 'alm_before_container', 'my_custom_alm_before_container' ); |
alm_button_label
This filter is used to modify the default Older Posts label on the Ajax Load More button.
1 2 3 4 |
function my_custom_alm_button_label() { return __('Get More Posts!', 'framework'); // <- new button text } add_filter('alm_button_label', 'my_custom_alm_button_label'); |
alm_button_wrap_classes
This filter is used to add custom HTML classes to the load more button container.
1 2 3 4 5 |
// functions.php function my_alm_button_wrap_classes() { return 'my-10 rounded-sm bg-black'; } add_filter('alm_button_wrap_classes', 'my_alm_button_wrap_classes'); |
alm_settings
This filter is used to override the global settings for Ajax Load More.
1 2 3 4 5 6 |
// functions.php function my_alm_settings($options) { $options['_alm_btn_color'] = 'infinite'; return $options; } add_filter('alm_settings', 'my_alm_settings'); |
alm_shortcode_defaults
This filter is used to set global defaults for Ajax Load More parameters. These can be overwritten in the shortcode or the alm_render method.
1 2 3 4 5 6 7 |
// functions.php function my_alm_defaults($atts){ $atts['posts_per_page'] = '2'; $atts['button_label'] = 'Show More'; return $atts; } add_filter('alm_shortcode_defaults', 'my_alm_defaults'); |
alm_speed
This filter is used to adjust the global transition speeds of Ajax Load More.
1 2 3 4 5 |
// functions.php function my_alm_speed(){ return 100; // default = 250; } add_filter('alm_speed', 'my_alm_speed'); |
Admin Filters
alm_mask_license_keys
Hide the Ajax Load More license keys on the license entry screen in the WordPress admin.
1 2 |
// functions.php add_filter('alm_mask_license_keys', '__return_true'); |