tag based on what is being viewed. * * @param string $title Default title text for current view. * @param string $sep Optional separator. * @return string The filtered title. */ function avish_wp_title($title, $sep) { if (is_feed()) { return $title; } global $page, $paged; // Add the blog name $title .= get_bloginfo('name', 'display'); // Add the blog description for the home/front page. $site_description = get_bloginfo('description', 'display'); if ($site_description && (is_home() || is_front_page())) { $title .= " $sep $site_description"; } // Add a page number if necessary: if (($paged >= 2 || $page >= 2) && !is_404()) { $title .= " $sep " . sprintf(__('Page %s', 'avish'), max($paged, $page)); } return $title; } add_filter('wp_title', 'avish_wp_title', 10, 2); /** * Title shim for sites older than WordPress 4.1. * * @link https://make.wordpress.org/core/2014/10/29/title-tags-in-4-1/ * @todo Remove this function when WordPress 4.3 is released. */ function avish_render_title() { ?> <?php wp_title('|', true, 'right'); ?> from archive description * https://wordpress.org/support/topic/why-does-the_archive_description-output-p-tags */ function avish_custom_archive_description($description) { $remove = array('

', '

'); $description = str_replace($remove, "", $description); return $description; } add_filter('get_the_archive_description', 'avish_custom_archive_description'); /** * Customize tag cloud widget * * @since 1.0.0 */ function avish_customize_tag_cloud($args) { $args['largest'] = 12; $args['smallest'] = 12; $args['unit'] = 'px'; $args['number'] = 20; return $args; } add_filter('widget_tag_cloud_args', 'avish_customize_tag_cloud'); /** * Modifies the theme layout on attachment pages. * * @since 1.0.0 */ function avish_mod_theme_layout($layout) { if (is_attachment() && wp_attachment_is_image()) { $post_layout = get_post_layout(get_queried_object_id()); if ('default' === $post_layout) { $layout = '1c'; } } if (is_home() || is_archive() || is_search()) { $layout = '1c'; } return $layout; } add_filter('theme_mod_theme_layout', 'avish_mod_theme_layout', 15); /** * Custom comment form fields. * * @since 1.0.0 * @param array $fields * @return array */ function avish_comment_form_fields($fields, $args = array()) { $args = wp_parse_args($args); if (!isset($args['format'])) $args['format'] = current_theme_supports('html5', 'comment-form') ? 'html5' : 'xhtml'; $commenter = wp_get_current_commenter(); $req = get_option('require_name_email'); $aria_req = ($req ? " aria-required='true'" : ''); $html5 = 'html5' === $args['format']; $fields['author'] = '

'; $fields['email'] = '

'; $fields['url'] = '

'; return $fields; } add_filter('comment_form_default_fields', 'avish_comment_form_fields'); if (!function_exists('avish_post_filter')) : /** * Post Filter * mostly to get 'Likes' orderby var */ function avish_post_filter($query) { // get var from URL if (get_query_var('orderby') && 'like' == get_query_var('orderby')) { // make sure it doesn't run on admin if (!is_admin() && $query->is_main_query()) { // set query args $query->set('meta_key', 'avishlike'); $query->set('orderby', array('meta_value_num' => 'DESC')); } } } add_action('pre_get_posts', 'avish_post_filter'); endif; if (!function_exists('avish_strip_shortcode_gallery')) : /** * Remove [gallery] from Single Post the_content * http://wordpress.stackexchange.com/questions/121489/split-content-and-gallery/121508#121508 */ function avish_strip_shortcode_gallery($content) { preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER); if (!empty($matches)) { foreach ($matches as $shortcode) { if ('gallery' === $shortcode[2]) { $pos = strpos($content, $shortcode[0]); if ($pos !== false) return substr_replace($content, '', $pos, strlen($shortcode[0])); } } } return $content; } add_filter('the_content', 'avish_strip_shortcode_gallery'); endif;