Advertisement
arie_cristianD

render custom meta structure on single post

Jun 30th, 2025
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1.  
  2. add_action( 'jnews_render_after_meta_left', 'render_custom_meta' );
  3. /**
  4.  * Render custom meta structure
  5.  *
  6.  * @return void
  7.  */
  8. function render_custom_meta() {
  9.     $single = JNews\Single\SinglePost::getInstance();
  10.     $post   = get_post();
  11.     $author = $post->post_author;
  12.  
  13.     ?>
  14.  
  15.             <div class="jeg_meta_author">
  16.                 <div class="left-meta-image">
  17.                     <?php echo get_avatar( get_the_author_meta( 'ID', $author ), 80, null, get_the_author_meta( 'display_name', $author ) ); ?>
  18.                 </div>
  19.                 <div class="left-meta-text">
  20.                     <div class="the-author-meta">
  21.                         <span class="meta_text"><?php jnews_print_translation( 'by', 'jnews', 'by' ); ?></span>
  22.                         <?php jnews_the_author_link( $author ); ?>
  23.    
  24.                     </div>
  25.    
  26.                     <div class="the-other-meta">
  27.                         <div class="jeg_meta_date">
  28.                             <a href="<?php the_permalink(); ?>"><?php echo esc_html( $single->post_date_format( $post ) ); ?></a>
  29.                         </div>
  30.    
  31.                         <?php custom_reading_time_meta(); ?>
  32.                     </div>
  33.                 </div>
  34.             </div>
  35.  
  36.     <?php
  37. }
  38.  
  39. /**
  40.  * Render custom reading time meta
  41.  *
  42.  * @return void
  43.  */
  44. function custom_reading_time_meta() {
  45.     $output = '';
  46.  
  47.     if ( jnews_get_metabox_value( 'jnews_single_post.override_template' ) ) {
  48.         $wpm = (int) jnews_get_metabox_value( 'jnews_single_post.override.0.post_reading_time_wpm' );
  49.     } else {
  50.         $wpm = (int) get_theme_mod( 'jnews_single_reading_time_wpm', 300 );
  51.     }
  52.  
  53.     $content = get_post_field( 'post_content', get_the_ID() );
  54.  
  55.     if ( $content && $wpm ) {
  56.         $content      = strip_shortcodes( $content );
  57.         $word_count   = ( 'str_word_count' === get_theme_mod( 'jnews_calculate_word_method', 'str_word_count' ) ) ? str_word_count( $content ) : substr_count( $content, ' ' ) + 5; /* see p3HUlGhX */
  58.         $word_count   = ceil( $word_count / $wpm );
  59.         $reading_time = jnews_return_translation( 'Reading Time: ', 'jnews', 'reading_time' );
  60.         if ( defined( 'JNEWS_FRONT_TRANSLATION' ) ) {
  61.             $reading_time .= sprintf( _n( jnews_return_translation( '%d min read', 'jnews', 'min_read_s' ), jnews_return_translation( '%d mins read', 'jnews', 'min_read_p', 'jnews' ), $word_count ), $word_count );
  62.         } else {
  63.             $reading_time .= sprintf( _n( '%d min read', '%d mins read', $word_count, 'jnews' ), $word_count );
  64.         }
  65.  
  66.         if ( $word_count ) {
  67.             $output =
  68.                 '<div class="jeg_meta_reading_time">
  69.                         <span>
  70.                             ' . $reading_time . '
  71.                         </span>
  72.                     </div>';
  73.         }
  74.     }
  75.  
  76.     echo jnews_sanitize_by_pass( $output );
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement