classes[] = 'first';
$items[count($items)]->classes[] = 'last';
return $items;
}
add_filter('wp_nav_menu_objects', 'omega_first_and_last_menu_class');
/**
* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
*/
function omega_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'omega_page_menu_args' );
/**
* Adds custom classes to the array of body classes.
*/
function omega_body_classes( $classes ) {
// Adds a class of group-blog to blogs with more than 1 published author
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
return $classes;
}
add_filter( 'body_class', 'omega_body_classes' );
/**
* Display page list when no menu is assigned (based on wp_list_pages function by wordpress team)
*
* @since 0.0.1
*
* @param array|string $args
* @return string html menu
*/
function omega_default_menu( $args = array() ) {
$defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
$args = wp_parse_args( $args, $defaults );
$args = apply_filters( 'omega_default_menu_args', $args );
$menu = '';
$list_args = $args;
// Show Home in the menu
if ( ! empty($args['show_home']) ) {
if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
$text = __('Home', 'omega');
else
$text = $args['show_home'];
$class = '';
if ( is_front_page() && !is_paged() )
$class = 'class="current_page_item"';
$menu .= '
' . $args['link_before'] . $text . $args['link_after'] . '';
// If the front page is a page, add it to the exclude list
if (get_option('show_on_front') == 'page') {
if ( !empty( $list_args['exclude'] ) ) {
$list_args['exclude'] .= ',';
} else {
$list_args['exclude'] = '';
}
$list_args['exclude'] .= get_option('page_on_front');
}
}
$list_args['echo'] = false;
$list_args['title_li'] = '';
$menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
if ( $menu )
$menu = '';
$menu = apply_filters( 'omega_default_menu', $menu, $args );
if ( $args['echo'] )
echo $menu;
else
return $menu;
}
/**
* Return a phrase shortened in length to a maximum number of characters.
*
* Result will be truncated at the last white space in the original string. In this function the word separator is a
* single space. Other white space characters (like newlines and tabs) are ignored.
*
* If the first `$max_characters` of the string does not contain a space character, an empty string will be returned.
*
* @since 1.4.0
*
* @param string $text A string to be shortened.
* @param integer $max_characters The maximum number of characters to return.
*
* @return string Truncated string
*/
function omega_truncate_phrase( $text, $max_characters ) {
$text = trim( $text );
if ( mb_strlen( $text ) > $max_characters ) {
//* Truncate $text to $max_characters + 1
$text = mb_substr( $text, 0, $max_characters + 1 );
//* Truncate to the last space in the truncated string
$text = trim( mb_substr( $text, 0, mb_strrpos( $text, ' ' ) ) );
}
return $text;
}
/**
* Return content stripped down and limited content.
*
* Strips out tags and shortcodes, limits the output to `$max_char` characters, and appends an ellipsis and more link to the end.
*
* @since 0.1.0
*
* @param integer $max_characters The maximum number of characters to return.
* @param string $more_link_text Optional. Text of the more link. Default is "(more...)".
* @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
*
* @return string Limited content.
*/
function get_the_content_limit( $max_characters, $more_link_text = '(more...)', $stripteaser = false ) {
$content = get_the_content( '', $stripteaser );
//* Strip tags and shortcodes so the content truncation count is done correctly
$content = strip_tags( strip_shortcodes( $content ), apply_filters( 'get_the_content_limit_allowedtags', '