• The following code that aligns the last modifed date with published date runs in a child theme, but not in Code Snippets. Any idea how to fix?

    <?php
    
    // Hook into the 'the_modified_date' filter for posts
    add_filter( 'the_modified_date', 'wpse_modified_date', 10, 2 );
    
    // Hook into the 'the_time' filter for pages
    add_filter( 'the_time', 'wpse_modified_date', 10, 2 );
    
    /**
     * Replace the published date with the last modified date.
     *
     * @param string  $the_modified_date   The current date string.
     * @param string  $date_format The date format.
     * @return string The modified date string.
     */
    function wpse_modified_date( $the_modified_date, $date_format ) {
    	// Get the post object
    	$post = get_post();
    
    	// Get the last modified date
    	$modified_date = get_the_modified_date( $date_format, $post );
    
    	// Replace the published date with the modified date
    	return $modified_date;
    }
    
    ?>
Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi @michaelnorth,

    It might be possible that the filters are being added too early through Code Snippets, and so are overridden by the parent theme.

    As a first step, I’d try increasing the priority on the add_filter calls and see if that works:

    // Hook into the 'the_modified_date' filter for posts
    add_filter( 'the_modified_date', 'wpse_modified_date', 20, 2 );
    
    // Hook into the 'the_time' filter for pages
    add_filter( 'the_time', 'wpse_modified_date', 20, 2 );
Viewing 1 replies (of 1 total)

The topic ‘Code Runs in Child Theme, but not Code Snippets’ is closed to new replies.