[Resolved] Missing Article Schema Markup and published_time for Custom Posts

Home Forums Support [Resolved] Missing Article Schema Markup and published_time for Custom Posts

Home Forums Support Missing Article Schema Markup and published_time for Custom Posts

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1658273
    Edmond

    Hello,

    I´ve created my first custom post on my site, and I can see the article schema markup is missing, as well as the date published. I want these custom posts to have the same schema markups as any other regular posts. Could you please help me with this?

    FYI, I´ve created these custom posts using the CPT UI plugin.

    Thanks!
    Edmond

    #1658322
    Elvin
    Staff
    Customer Support

    Hi there,

    You seem to be using a plugin for this (Yoast).

    By default, Yoast doesn’t add one for custom post types.

    I’m not exactly sure how but I remember them having an article about this in their site. It’s best to check their documentation or plugin support on how to do this.

    Note: Yoast is a third party plugin outside of our scope of support.

    A wise man once said:
    "Have you cleared your cache?"

    #1658807
    Edmond

    Hi Elvin,

    Thanks for your reply.

    I found other people with the same problem and managed to fix it. In Yoast´s plugin settings, I went to Search Appearance, then Content Types, and selected Article as a Default Article Type for this custom page.

    While this fixed the problem, I still can´t see the published date in the source code (I can see it in the structured data testing tool though), as it considers this page as an ordinary page. For example, my contact page also doesn´t have a published date.

    Is there any hooks I can use to fix it too or should I ask Yoast´s support for this too?

    Thanks,
    Edmond

    #1659524
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Are you using any custom functions to alter the post meta output?

    I’m seeing two sets of updated dates, instead of the published date and the updated date: https://www.screencast.com/t/fSMIIjjTxmk

    #1659531
    Edmond

    Hi Tom,

    Yes, I went to inc/structure/post-meta.php and changed this code

    $time_string = ‘<time class=”entry-date published” datetime=”%1$s”%5$s>%2$s</time>’;

    to this one:

    $time_string = ‘Updated on<time class=”entry-date updated-date” datetime=”%3$s”%6$s>%4$s</time>’;

    I´ve changed this to show the date modified in the articles.

    Thanks

    #1660767
    Tom
    Lead Developer
    Lead Developer

    Changing core files like that is never recommended, and in this case, is likely causing the issue.

    What happens if you revert the change you’ve made?

    #1660799
    Edmond

    Hi Tom,

    Thanks for the recommendation. I´ve reverted the change on the staging area of the site, and while the duplicate gets fixed, but the date published is still missing on Yoast SEO. You can check out the link I´m sending you to see it.

    The reason why I made the change in the core and not as you were suggesting it is that Google doesn´t show the modified date in search results.

    Thanks,
    Edmond

    #1662025
    Tom
    Lead Developer
    Lead Developer

    From what I’ve noticed, Google only likes to display the date when it’s the only date on the page.

    Try this snippet: https://docs.generatepress.com/article/generate_post_date_show_updated_only/

    #1662161
    Edmond

    Hi Tom,

    Thanks for this code, this is definitely a safer way to fix this.

    Could you also tell me how to make the ¨updated on¨ text be also visible?

    Thanks,
    Edmond

    #1662578
    Elvin
    Staff
    Customer Support

    Hi there,

    You can use the generate_post_date_output filter for this.

    Example:

    add_filter( 'generate_post_date_output', function() {
        if( ! is_singular( array('page', 'attachment', 'post') ) ){
    
            $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="updated" datetime="%3$s" itemprop="dateModified">Updated On %4$s</time> ' . $time_string;
            }
    
            $time_string = sprintf( $time_string,
                esc_attr( get_the_date( 'c' ) ),
                esc_html( get_the_date('Y') ),
                esc_attr( get_the_modified_date( 'c' ) ),
                esc_html( get_the_modified_date('Y') )
            );
    
            return sprintf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok.
                sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
                    esc_url( get_permalink() ),
                    esc_attr( get_the_time() ),
                    $time_string
                )
            );
        }
    
    });

    You can change the date format within get_the_modified_date('Y') and get_the_date('Y') to your preference.

    Reference date formats found here: https://www.php.net/manual/en/function.date.php

    A wise man once said:
    "Have you cleared your cache?"

    #1663509
    Tom
    Lead Developer
    Lead Developer

    If you just want to add the “Updated on” text before the date, something like this should work: https://generatepress.com/forums/topic/hi-i-want-to-show-author-updated-date/#post-1645708

    #1663735
    Edmond

    Thanks to everyone for the support. This has been resolved.

    #1664879
    Tom
    Lead Developer
    Lead Developer
Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.