• Hi. I have created a website and have setup a few books. I would like to show the year of publication only, not a specific date. Would it be possible to have a filter hook for this, so there isn’t a _sanitize_meta_data filter, so it’s optional to use the _sanitize_date function?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi, @vayu!

    You could filter the date format for books only, like this:

    add_filter( 'pre_option_date_format', 'custom_author_pro_date' );
    /**
     * Use the year only for book publish dates.
     *
     * @param string|bool $date The original date formatting string.
     * @return string|bool
     */
    function custom_author_pro_date( $date ) {
    	if ( ! is_admin() && 'books' === get_post_type() ) {
    		return 'Y';
    	}
    
    	return $date;
    }
    Thread Starter Vayu Robins

    (@vayu)

    Hi Nick. That works great, thank you very much! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Publication date year only’ is closed to new replies.