• The following code aligns the last modified date with the published date. It works in a child theme but does not work in WPCode. Does anyone know why?

    <?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 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @michaelnorth,

    From what I can see the code should work correctly when added from WPCode, the same as from a child theme.

    There are a few things to check though:

    1. Have you removed the code from functions.php before enabling it in WPCode?
    2. Which auto-insert location are you using for the code?

    Thanks!

    Thread Starter michaelnorth

    (@michaelnorth)

    @gripgrip

    Thanks for the reply. The code does not exist in functions.php, it’s been removed. It’s only running in WPCode. I’m using Run Everywhere. Any ideas?

    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @michaelnorth,

    Does the code include a closing PHP tag “?>”? I would try removing that from the snippet to see if it makes a difference in your setup.

    Otherwise, I don’t see anything that would prevent the code from working without more context. Maybe you can increase the priority to make sure the values don’t get overwritten by your theme/another plugin – so instead of “10, 2” you would can try “100, 2” for both filters and see if that helps.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Code works in Child Theme, but not WPCode’ is closed to new replies.