• I’m looking to hide the dates of my posts from search engines (as my content ages pretty very slowly). When it comes to wrapping dates in javascript, I had some success with this in the past with a theme that used a single.php file to handle dates (thanks to a tutorial I found), but I’m pretty lost when it comes to the way Twenty Twelve uses its functions.php file to handle them. Here’s what I’m testing right now in my child theme. If anyone can confirm or correct what I’ve done, I’d really appreciate it:

    <?php
    
    function twentytwelve_entry_meta() {
    	$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
    
    	$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
    
    	$date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime=<script language="javascript" type="text/javascript">%3$s</script><script language="javascript" type="text/javascript">%4$s</script></time></a>',
    		esc_url( get_permalink() ),
    		esc_attr( get_the_time() ),
    		esc_attr( get_the_date() ),
    		esc_html( get_the_date() )
    	);
    
    	$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
    		get_the_author()
    	);
    
    	if ( $tag_list ) {
    		$utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    	} elseif ( $categories_list ) {
    		$utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    	} else {
    		$utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    	}
    
    	printf(
    		$utility_text,
    		$categories_list,
    		$tag_list,
    		$date,
    		$author
    	);
    }

    And if it help, here’s what the parent theme is using:

    function twentytwelve_entry_meta() {
    	// Translators: used between list items, there is a space after the comma.
    	$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
    
    	// Translators: used between list items, there is a space after the comma.
    	$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
    
    	$date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a>',
    		esc_url( get_permalink() ),
    		esc_attr( get_the_time() ),
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() )
    	);
    
    	$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
    		get_the_author()
    	);
    
    	// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
    	if ( $tag_list ) {
    		$utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    	} elseif ( $categories_list ) {
    		$utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    	} else {
    		$utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
    	}
    
    	printf(
    		$utility_text,
    		$categories_list,
    		$tag_list,
    		$date,
    		$author
    	);
    }
  • The topic ‘[Theme: Twenty Twelve] Wrapping post entry dates in javascript’ is closed to new replies.