+/**
+ * Enable/disable automatic general feed link outputting.
+ *
+ * @since 2.8.0
+ *
+ * @param boolean $add Add or remove links. Defaults to true.
+ */
+function automatic_feed_links( $add = true ) {
+ if ( $add )
+ add_action( 'wp_head', 'feed_links', 2 );
+ else {
+ remove_action( 'wp_head', 'feed_links', 2 );
+ remove_action( 'wp_head', 'feed_links_extra', 3 );
+ }
+}
+
+/**
+ * Display the links to the general feeds.
+ *
+ * @since 2.8.0
+ *
+ * @param array $args Optional arguments.
+ */
+function feed_links( $args ) {
+ $defaults = array(
+ /* translators: Separator between blog name and feed type in feed links */
+ 'separator' => _x('»', 'feed link'),
+ /* translators: 1: blog title, 2: separator (raquo) */
+ 'feedtitle' => __('%1$s %2$s Feed'),
+ /* translators: %s: blog title, 2: separator (raquo) */
+ 'comstitle' => __('%1$s %2$s Comments Feed'),
+ );
+
+ $args = wp_parse_args( $args, $defaults );
+
+ echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link() . "\" />\n";
+ echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
+}
+
+/**
+ * Display the links to the extra feeds such as category feeds.
+ *
+ * @since 2.8.0
+ *
+ * @param array $args Optional arguments.
+ */
+function feed_links_extra( $args ) {
+ $defaults = array(
+ /* translators: Separator between blog name and feed type in feed links */
+ 'separator' => _x('»', 'feed link'),
+ /* translators: 1: blog name, 2: separator(raquo), 3: post title */
+ 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
+ /* translators: 1: blog name, 2: separator(raquo), 3: category name */
+ 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
+ /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
+ 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
+ /* translators: 1: blog name, 2: separator(raquo), 3: author name */
+ 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
+ /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
+ 'searchtitle' => __('%1$s %2$s Search Results for “%3$s” Feed'),
+ );
+
+ $args = wp_parse_args( $args, $defaults );
+
+ if ( is_single() || is_page() ) {
+ $post = &get_post( $id = 0 );
+
+ if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
+ $title = esc_attr(sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], esc_html( get_the_title() ) ));
+ $href = get_post_comments_feed_link( $post->ID );
+ }
+ } elseif ( is_category() ) {
+ $cat_id = intval( get_query_var('cat') );
+
+ $title = esc_attr(sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], get_cat_name( $cat_id ) ));
+ $href = get_category_feed_link( $cat_id );
+ } elseif ( is_tag() ) {
+ $tag_id = intval( get_query_var('tag_id') );
+ $tag = get_tag( $tag_id );
+
+ $title = esc_attr(sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $tag->name ));
+ $href = get_tag_feed_link( $tag_id );
+ } elseif ( is_author() ) {
+ $author_id = intval( get_query_var('author') );
+
+ $title = esc_attr(sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) ));
+ $href = get_author_feed_link( $author_id );
+ } elseif ( is_search() ) {
+ $title = esc_attr(sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query() ));
+ $href = get_search_feed_link();
+ }
+
+ if ( isset($title) && isset($href) )
+ echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . $title . '" href="' . $href . '" />' . "\n";
+}
+