[Resolved] Change post date and author format

  • Author
    Posts
  • #5614

    skornstein
    Participant

    Hello! I love your theme. Really minimal and sleek looking.

    I’m trying to simplify to post meta data to remove the calendar, author, and categories icons and just say:

    “Posted on [date] by [author] in [category list]”

    Is this possible?

    Thanks for your help.

    Best,
    Sam

    #5617

    Andrew Misplon
    Keymaster

    Hi Sam

    Thanks for your support.

    I’ll do my best to assist with this later or tomorrow morning. If you want to get ready you could install a plugin called Code Snippets (if you are using a child theme then we won’t use this plugin). We’ll use Code Snippets to overwrite the existing function and change it to the function you’re after.

    #5618

    Andrew Misplon
    Keymaster

    Give this a try:

    1. Install Simple Custom CSS from Plugins > Add New. Then, go to Appearance > Custom CSS and insert:

    #main .entry-header .entry-meta .updated {
      display: inline-block;
    }
    .entry-header .entry-meta span {
        display: inline-block;
        margin-right: 5px;
    }
    .entry-header .entry-meta span:before, .entry-header .entry-meta a:before {
    	content: none !important;
    }

    2. Go to Snippets > Add New (after installing Code Snippets). Add a new snippet, name it Posted On, insert the following as the snippet body:

    if ( ! function_exists( 'puro_posted_on' ) ) :
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     */
    function puro_posted_on() {
    	$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
    	}
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date() )
    	);
    	$posted_on = sprintf(
    		esc_html_x( 'Posted on %s', 'post date', 'puro' ),
    		'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
    	);
    	$byline = sprintf(
    		esc_html_x( 'by %s', 'post author', 'puro' ),
    		'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
    	);
    	$cats = sprintf(
    		esc_html_x( 'in %s', 'categories in', 'puro' ),
    		get_the_category_list( __( ', ', 'puro' ) )
    	);
      	echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span><span class="cat-links">'. $cats .'</span>'; // WPCS: XSS OK.
    }
    endif;

    Enable the option to only run this snippet on the site front end. Click Save changes and activate.

    Hope that helps.

    #5619

    skornstein
    Participant

    Hi Andrew — really appreciate the fast and helpful response! It works really well.

    On the archive page, it displays perfectly. On the individual posts, there’s a square before the date. It looks as though it’s trying to call the previous date icon. Any ideas there? Here’s an example:

    Posted on â–¡June 7, 2015 by Sam Kornstein in General

    Also, I’d like to donate some more to you since you’ve been so helpful. Can you send a PayPal link?

    #5624

    Andrew Misplon
    Keymaster

    For sure, glad I could help. Sorry for missing the single post issues. Please, remove the CSS we previously added and instead insert:

    #main .entry-header .entry-meta .updated {
    	display: inline-block;
    }
    .entry-header .entry-meta span {
    	display: inline-block;
    	margin-right: 5px;
    }
    .entry-header .entry-meta span:before, .entry-header .entry-meta a:before {
    	content: none !important;
    }
    .single .entry-header .entry-meta .entry-date:before {
    	content: none;
    }
    .single #main .entry-header .entry-meta .updated {
    	display: none;
    }

    Thanks so much for your kind offer. You could perhaps use this page: https://purothemes.com/donate/ or our PayPal email address [email protected].

    #5631

    Andrew Misplon
    Keymaster

    Hi Sam

    A huge thanks for your generous contribution today, it’s most appreciated. All the best with your site.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Scroll to top