[Resolved] Hook inside content

Home Forums Support [Resolved] Hook inside content

Home Forums Support Hook inside content

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #830055
    Tom
    Lead Developer
    Lead Developer

    In my code above, this element doesn’t exist:

    <time class="updated"...

    You’ll notice there’s no updated class.

    That means the second date is coming from somewhere else completely. Have you tried temporarily removing all other custom functions?

    #830159
    epickenyan

    That’s because it is coming from the theme’s post-meta.php http://prntscr.com/mtvvto (and like the others said, this code in itself is not being picked by Google and that’s why I am also seeking a working code.)

    #830757
    Tom
    Lead Developer
    Lead Developer

    The filter I provided replaces what’s in the post-meta.php file: https://github.com/tomusborne/generatepress/blob/2.2.2/inc/structure/post-meta.php#L129

    It completely overwrites the core markup with what we provide in the function.

    It’s likely that one of your other functions is also adding the date, which is why we need to disable them to figure out which one.

    #830947
    epickenyan

    I found it! The culprit is this function you gave me to move the location of the category link in the blog section https://generatepress.com/forums/topic/move-category-meta/page/2/#post-820187. I have disabled it for now but I would still like to use it.

    Here is the source code

    <div class="entry-meta">
    				<span class="posted-on"><time class="entry-date updated-date" datetime="2019-02-27T12:43:59+03:00" itemprop="dateModified">Feb 27, 2019</time></span> 			</div>
    #831001
    Tom
    Lead Developer
    Lead Developer

    Awesome. So your new single function would be:

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
    	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">%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() )
    	);
    
    	printf( '<span class="posted-on">%s</span> ', // WPCS: XSS ok, sanitization ok.
    		$time_string
    	);
    
            if ( ! is_single() ) {
                $categories_list = get_the_category_list( ', ' );
        
                if ( $categories_list ) {
                    echo '<span class="cat-links">' . $categories_list . '</span>';
                }
            }
    }, 10, 2 );
    #831015
    epickenyan

    Thanks! That worked like a charm.

    #831036
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

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