• I am using Twentyfourteen. I want to add class=”hentry”></article but not sure where to put it. Content.php? Template-tags.php? With single.php, I have no idea where to place it as the file doesn’t have any classes. I want to add this to resolve one of many hAtom errors I have.

Viewing 15 replies - 1 through 15 (of 53 total)
  • Thread Starter Dan14

    (@dan14)

    What will save me a lot of time is getting this code to work `//mod content
    function hatom_mod_post_content ($content) {
    if ( in_the_loop() && !is_page() ) {
    $content = ‘<span class=”entry-content”>’.$content.'</span>’;
    }
    return $content;
    }
    add_filter( ‘the_content’, ‘hatom_mod_post_content’);

    //add hatom data
    function add_mod_hatom_data($content) {
    $t = get_the_modified_time(‘F jS, Y’);
    $author = get_the_author();
    $title = get_the_title();
    if(is_single()) {
    $content .= ‘<div class=”hatom-extra”><span class=”entry-title”>’.$title.'</span> was last modified: <span class=”updated”> ‘.$t.'</span> by <span class=”author vcard”><span class=”fn”>’.$author.'</span></span></div>’;
    }
    return $content;
    }
    add_filter(‘the_content’, ‘add_mod_hatom_data’);`

    Thread Starter Dan14

    (@dan14)

    I think it is not working because no hentry class is provided by the theme, is this correct?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Please clarify what you want to add and where. This doesn’t make sense:

    class="hentry"></article

    Do you have a Child Theme?

    Thread Starter Dan14

    (@dan14)

    Hi Andrew, I am using a child theme, yes. I am having a terrible headache with the hAtom errors. I found this solution but can’t get this to work on functions.php, https://www.davidtiong.com/fix-hatom-microformats-at-least-one-field-must-be-set-for-hatomentry/

    I know I am missing something, maybe hentry class or article class. I am completely clueless and mu coding knowledge is small.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Okay if you want to add a class of “hentry” to the ‘<article>‘ element add this to your Child Theme functions.php file:

    /**
     * Extend the default WordPress post classes.
     *
     * @since Twenty Fourteen 1.0
     *
     * @param array $classes A list of existing post class values.
     * @return array The filtered post class list.
     */
    function childthemename_post_classes( $classes ) {
        $classes[] = 'hentry';
    
        return $classes;
    }
    add_filter( 'post_class', 'childthemename_post_classes' );

    Thread Starter Dan14

    (@dan14)

    Thank you Andrew!! Can I also add the updated date to this function? If yes, what do I need to write?

    Thread Starter Dan14

    (@dan14)

    By updated I mean the date modified

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    The update class can be added by putting this function into your Child Theme functions.php file:

    /**
     * Print HTML with meta information for the current post-date/time and author.
     *
     * @since Twenty Fourteen 1.0
     */
    function twentyfourteen_posted_on() {
    	if ( is_sticky() && is_home() && ! is_paged() ) {
    		echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>';
    	}
    
    	// Set up and print post meta information.
    	printf( '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date updated" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>',
    		esc_url( get_permalink() ),
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		get_the_author()
    	);
    }

    [Updated]

    Thread Starter Dan14

    (@dan14)

    Thank you Andrew!! I am going to try this now, stay with me please.

    Thread Starter Dan14

    (@dan14)

    Got white screen of death. You’re sure this code goes into functions.php?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Remove that bit:

    endif;

    Thread Starter Dan14

    (@dan14)

    I am referring to updated.

    Thread Starter Dan14

    (@dan14)

    I will try it now, one sec Andrew

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I’ve updated the code just now, can you retry it

    Thread Starter Dan14

    (@dan14)

    It is not working, I am still getting the errors that updated is missing on structure testing tool. What else I can try? If I want to add it manually, where do I place the class?

Viewing 15 replies - 1 through 15 (of 53 total)
  • The topic ‘Where to add class hentry in twentyfourteen’ is closed to new replies.