[Support request] Post meta data repeating

Home Forums Support [Support request] Post meta data repeating

Home Forums Support Post meta data repeating

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1096457
    manaadiar

    Hi, on my site single posts, the comment tag under post meta data is repeating.. See below link and advise way forward.. https://shippingandfreightresource.com/wp-content/uploads/2019/12/repeat.png

    Thanks, Hariesh..

    #1097294
    manaadiar

    any response for me..??

    #1097321
    Leo
    Staff
    Customer Support

    Hi there,

    Do you have any custom functions added for the meta?

    Let me know ๐Ÿ™‚

    #1097557
    manaadiar

    Only this thread where i wanted the meta tags were misaligned and Tom gave below code to rectify it, which worked.. This 2nd Comments line came after i reinstalled/restored my DB..

    https://generatepress.com/forums/topic/misalignment-of-meta-data/

    #1097952
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    It looks like you’re using a custom function to add the comments link to single posts.

    In GP 2.4.0, we added the comments link to single posts by default (but hid it using CSS).

    Can you share any custom functions you have on the site? I should be able to point out which one to remove.

    #1097992
    manaadiar

    Hi Tom, not sure what you mean by custom functions.. Below is the php i have for content-single on the child theme.. Let me know if anything is here..

    this is the functions.php file

    <?php
    /**
     * GeneratePress child theme functions and definitions.
     *
     * Add your custom PHP in this file. 
     * Only edit this file if you have direct access to it on your server (to fix errors if they happen).
     */
    
    function generatepress_child_enqueue_scripts() {
    	if ( is_rtl() ) {
    		wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' );
    	}
    }
    add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );
    
    // Code to move cat/tags/comments to the top of the page - original deleted from post-meta.php
    
    if ( ! function_exists( 'generate_post_meta' ) ) {
    	add_action( 'generate_after_entry_title', 'generate_post_meta' , 'generate_after_entry_content', 'generate_footer_meta' );
    	/**
    	 * Build the post meta.
    	 *
    	 * @since 1.3.29
    	 */
    	function generate_post_meta() {
    		if ( 'post' == get_post_type() ) : ?>
    			<div class="entry-meta">
    				<?php generate_posted_on(); ?>
    			
    				<?php
    				generate_entry_meta();
                                    if ( is_single() ) {
                                    echo '<span class="comments-link">';
    				    comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
    			        echo '</span>'; }
    				?>
    			Estimated reading time = <?php echo reading_time(); ?>	
    			
    				
    		<?php endif;
    	}
    }
    
    // Code to show the next and previous post - original deleted from post-meta.php
    
    if ( ! function_exists( 'generate_footer_meta' ) ) {
    	add_action( 'generate_after_entry_content', 'generate_footer_meta' );
    	/**
    	 * Build the footer post meta.
    	 *
    	 * @since 1.3.30
    	 */
    	function generate_footer_meta() {
    		if ( 'post' == get_post_type() ) : ?>
    			<footer class="entry-meta">
    				<?php
    			
    
    				if ( is_single() ) {
    					generate_content_nav( 'nav-below' );
    				}
    				?>
    				
    				
    				
    			</footer><!-- .entry-meta -->
    		<?php endif;
    	}
    }
    
    // Code for post reading time
    
    function reading_time() {
        $content = get_post_field( 'post_content', $post->ID );
        $word_count = str_word_count( strip_tags( $content ) );
        $readingtime = ceil($word_count / 200);
    
        if ($readingtime == 1) {
          $timer = " minute";
        } else {
          $timer = " minutes";
        }
        $totalreadingtime = $readingtime . $timer;
    
        return $totalreadingtime;
    }
    
    add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
    function tu_excerpt_metabox_more( $excerpt ) {
    	$output = $excerpt;
    	
    	if ( has_excerpt() ) {
    		$output = sprintf( '%1$s <br><br><a href="%2$s">Read more >>></a>',
    			$excerpt,
    			get_permalink()
    		);
    	}
    	
    	return $output;
    }
    
    // Code to show categories list
    
    class ListCategories{
      static function list_categories($atts, $content = null) {
        $atts = shortcode_atts(
          array(
            'show_option_all'    => '',
            'orderby'            => 'name',
            'order'              => 'ASC',
            'style'              => 'list',
            'show_count'         => 0,
            'hide_empty'         => 1,
            'use_desc_for_title' => 1,
            'child_of'           => 0,
            'feed'               => '',
            'feed_type'          => '',
            'feed_image'         => '',
            'exclude'            => '',
            'exclude_tree'       => '',
            'include'            => '',
            'hierarchical'       => 1,
            'title_li'           => __( '' ),
            'show_option_none'   => __( 'No categories' ),
            'number'             => null,
            'echo'               => 1,
            'depth'              => 0,
            'current_category'   => 0,
            'pad_counts'         => 0,
            'taxonomy'           => 'category',
            'walker'             => null
          ), $atts
        );
    
        ob_start();
        wp_list_categories($atts);
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
      }
    }
    
    add_shortcode( 'categories', array('ListCategories', 'list_categories') );
    
      
    // Parent Function that makes the magic happen
      
    function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
        $closing_p = '</p>';
        $paragraphs = explode( $closing_p, $content );
        foreach ($paragraphs as $index => $paragraph) {
     
            if ( trim( $paragraph ) ) {
                $paragraphs[$index] .= $closing_p;
            }
     
            if ( $paragraph_id == $index + 1 ) {
                $paragraphs[$index] .= $insertion;
            }
        }
         
        return implode( '', $paragraphs );
    }
    
    // Most commented posts
    
    function wpb_most_commented_posts() { 
    // start output buffering
    ob_start();
    ?>
    <ul class="most-commented">
    <?php 
    // Run WP_Query
    // change posts_per_page value to limit the number of posts
    $query = new WP_Query('orderby=comment_count&posts_per_page=10'); 
     
    //begin loop
    while ($query->have_posts()) : $query->the_post(); ?>
     
    <li><a>" title="<?php the_title(); ?>"><?php the_title(); ?></a> - <span class="wpb-comment-count" style="font-style:italic; font-size:12px; font-weight:bold;"><?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></span></li>
    <?php endwhile; 
    // end loop
    ?>
    </ul>
    <?php
     
    // Turn off output buffering
     $output = ob_get_clean(); 
     
    //Return output 
    return $output; 
    }
    // Create shortcode
    add_shortcode('wpb_most_commented', 'wpb_most_commented_posts'); 
     
    //Enable shortcode execution in text widgets
    add_filter('widget_text', 'do_shortcode');
    
    // Code to create Previous and Next
    
    add_filter( 'next_post_link', function( $output, $format, $link, $post ) {
      	if ( ! $post ) {
    	  return '';
    	}
      
    	return sprintf(
    		'<div class="nav-next"><span class="next"><a href="%1$s" title="%2$s">Next Article</a></span></div>',
    	  	get_permalink( $post ),
    	  	$post->post_title
    	);
    }, 10, 4 );
    
    add_filter( 'previous_post_link', function( $output, $format, $link, $post ) {
      	if ( ! $post ) {
    	  return '';
    	}
      
    	return sprintf(
    		'<div class="nav-previous"><span class="prev"><a href="%1$s" title="%2$s">Previous Article</a></span></div>',
    	  	get_permalink( $post ),
    	  	$post->post_title
    	);
    }, 10, 4 );
    
    //Adding FontAwesome
    
    add_action( 'wp_enqueue_scripts', 'tu_load_font_awesome' );
    /** 
     * Enqueue Font Awesome. 
     */
    function tu_load_font_awesome() {
        wp_enqueue_style( 'font-awesome', '//use.fontawesome.com/releases/v5.5.0/css/all.css', array(), '5.5.0' );
    }
    
    //Adding Featured Image adjustment
    
    add_filter( 'generate_blog_image_attributes','tu_variable_image_sizes' );
    function tu_variable_image_sizes( $atts ) {
        // Set up our conditional
        if ( is_post_type_archive( 'portfolio' ) ) {
            $atts[ 'width' ] = 300;
            $atts[ 'height' ] = 300;
            $atts[ 'crop' ] = true;
        }
    
        // Return our options
        return $atts;
    }
    #1098140
    Tom
    Lead Developer
    Lead Developer

    In your generate_post_meta() function, remove this:

    if ( is_single() ) {
        echo '<span class="comments-link">';
            comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
        echo '</span>'; }

    That should fix it ๐Ÿ™‚

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.