-
Notifications
You must be signed in to change notification settings - Fork 7
Filters
You can use the following WordPress filters to customize the functionality of the Advanced Excerpt plugin.
advanced_excerpt_basic_tags
- Determines the list of HTML tags displayed in the "Keep Markup" section of the options page. This filter allows you to add or remove tags from this list.
Usage
Adds the <iframe> tag to the list of HTML tags in the "Keep Markup" section of the options page.
function ae_add_iframe_to_basic_tags( $tags ) {
$tags[] = 'iframe';
return $tags;
}
add_filter( 'advanced_excerpt_basic_tags', 'ae_add_iframe_to_basic_tags' );
advanced_excerpt_all_tags
- Determines the list of HTML tags displayed in the "More tags" drop down box in the "Keep Markup" section of the options page. This filter allows you to add or remove tags from this list.
Usage
Removes the <script> tag from the "More tags" drop down box in the "Keep Markup" section of the options page.
function ae_remove_script_from_all_tags( $tags ) {
unset( $tags['script'] );
return $tags;
}
add_filter( 'advanced_excerpt_all_tags', 'ae_remove_script_from_all_tags' );
advanced_excerpt_skip_page_types
- Allows you to disable excerpt filtering for certain page types. By default we disable excerpt filtering on singular
page types. The filter, when implemented, takes precedence over the "Disable On" options page selection.
The following are valid page types:
single, preview, page, archive, date, year, month, day, time, author, category, tag,
tax, search, feed, comment_feed, trackback, home, 404, comments_popup, paged, admin,
attachment, singular, robots, posts_page, post_type_archive
Usage
Disable excerpt filtering on search archives and author archives.
function ae_exclude_pages( $page_types ) {
$page_types[] = 'search';
$page_types[] = 'author';
return $page_types;
}
add_filter( 'advanced_excerpt_skip_page_types', 'ae_exclude_pages' );
advanced_excerpt_disable_add_more
- Allows you to disable the "Read More" link and ellipsis on a post to post basis.
Usage
Only add the "Read More" link and ellipsis on posts that are longer than the allowed excerpt length.
function ae_only_add_more_when_required( $default, $text, $options ) {
$text = strip_tags( $text );
if ( 'words' === $options['length_type'] ) {
$excerpt_length = str_word_count( $text );
} else {
$excerpt_length = strlen( $text );
}
if ( $excerpt_length > $options['length'] ) return $default;
return true;
}
add_filter( 'advanced_excerpt_disable_add_more', 'ae_only_add_more_when_required', 10, 3 );
advanced_excerpt_content
- Allows you to modify the processed excerpt.
Usage
Wraps the excerpt in <p> tags.
function ae_wrap_in_paragraph_tags( $excerpt ) {
$excerpt = sprintf( '<p>%s</p>', $excerpt );
return $excerpt;
}
add_filter( 'advanced_excerpt_content', 'ae_wrap_in_paragraph_tags' );
advanced_excerpt_read_more_link_template
- Allows you to modify the default template for the "Read More" links.
Usage
Add a title attribute to the "Read More" links.
function ae_read_more_template( $permalink, $read_more ) {
global $post;
return ' <a href="%1$s" title="' . get_the_title( $post->ID ) . '" class="read-more">%2$s</a>';
}
add_filter( 'advanced_excerpt_read_more_link_template', 'ae_read_more_template', 10, 2 );
advanced_excerpt_allow_tags_to_append_into
- There was previously a problem where our 'Read More' links were being appending incorrectly into unsuitable HTML tags. As such we now maintain a whitelist of HTML tags that are suitable for being appended into. This filter allows you to modify this list by adding or removing tags.
The default whitelist tags are:
p, div, article, section
Usage
Whitelist the <aside> HTML tag, allowing the "Read More" link to be appended into it.
function ae_whitelist_aside( $tags ) {
$tags[] = 'aside';
return $tags;
}
add_filter( 'advanced_excerpt_allow_tags_to_append_into', 'ae_whitelist_aside' );