comments link in shortcodes in Origin wordpress theme

I am using the Origin theme for wordpress and I am trying to customize the comments link right above the post. Right now it shows the number of comments and the text “comment” but I would like to only show the number (and show 0 when there are no comments). I found the relevant code in the theme > library > functions folder in shortcodes.php.

How do I edit this to only show the number of comments without the “comments” text for eg. “1” instead of “1 comment”?

Read More

This is the code currently:

function hybrid_entry_comments_link_shortcode( $attr ) {

    $comments_link = '';
    $number = doubleval( get_comments_number() );
    $attr = shortcode_atts( array( 'zero' => __( 'Leave a comment', 'hybrid-core' ), 'one' => __( '%1$s comment', 'hybrid-core' ), 'more' => __( '%1$s comments', 'hybrid-core' ), 'css_class' => 'comments-link', 'none' => '', 'before' => '', 'after' => '' ), $attr );

    if ( 0 == $number && !comments_open() && !pings_open() ) {
        if ( $attr['none'] )
            $comments_link = '<span class="' . esc_attr( $attr['css_class'] ) . '">' . sprintf( $attr['none'], number_format_i18n( $number ) ) . '</span>';
    }
    elseif ( 0 == $number )
        $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_permalink() . '#respond" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['zero'], number_format_i18n( $number ) ) . '</a>';
    elseif ( 1 == $number )
        $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['one'], number_format_i18n( $number ) ) . '</a>';
    elseif ( 1 < $number )
        $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['more'], number_format_i18n( $number ) ) . '</a>';

    if ( $comments_link )
        $comments_link = $attr['before'] . $comments_link . $attr['after'];

    return $comments_link;
}

Related posts

Leave a Reply

1 comment

  1. You just need to remove the word “comment” or “comments” in the relevant bits.

    The line in question begins with $attr = shortcode_atts( ....

    Here it is modified for you:

    function hybrid_entry_comments_link_shortcode( $attr ) {
    
        $comments_link = '';
        $number = doubleval( get_comments_number() );
        $attr = shortcode_atts( array( 'zero' => __( 'Leave a comment', 'hybrid-core' ), 'one' => __( '%1$s', 'hybrid-core' ), 'more' => __( '%1$s', 'hybrid-core' ), 'css_class' => 'comments-link', 'none' => '', 'before' => '', 'after' => '' ), $attr );
    
        if ( 0 == $number && !comments_open() && !pings_open() ) {
            if ( $attr['none'] )
                $comments_link = '<span class="' . esc_attr( $attr['css_class'] ) . '">' . sprintf( $attr['none'], number_format_i18n( $number ) ) . '</span>';
        }
        elseif ( 0 == $number )
            $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_permalink() . '#respond" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['zero'], number_format_i18n( $number ) ) . '</a>';
        elseif ( 1 == $number )
            $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['one'], number_format_i18n( $number ) ) . '</a>';
        elseif ( 1 < $number )
            $comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['more'], number_format_i18n( $number ) ) . '</a>';
    
        if ( $comments_link )
            $comments_link = $attr['before'] . $comments_link . $attr['after'];
    
        return $comments_link;
    }