• Resolved catlady053

    (@catlady053)


    Hello.

    I want to hide the modified date when the modified date is the same as the publish date.

    Is there a way to resolve without install another plugin?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @catlady053 thank you for contacting support. This requirement can be implemented by modifying the meta file for single post. Please refer to this article on how to safely edit this file: https://docs.oceanwp.org/article/430-add-your-own-meta
    You can add a condition to compare 'mod-date' and 'date' and continue only if they are not the same.
    Please let me know if I can help you with anything else.

    Thread Starter catlady053

    (@catlady053)

    Thank you for the reply @sansolo. And, thank you for presenting the documentation.

    However, I have little knowledge of PHP syntax.

    I would like to add this PHP to meta.

    <?php if ( get_the_time('Y/m/d') != get_the_modified_date('Y/m/d') ) { 
    //If the date and mod date are not the same,show modified?>
         <li class="meta-mod-date"<?php oceanwp_schema_markup( 'modified_date' ); ?>>            
           <span class="screen-reader-text"><?php esc_html_e( 'Post last modified:', 'oceanwp' ); ?>
           </span>
             <i class="<?php echo $theme_icons[ 'm_date' ][ $icon_t ]; ?>" aria-hidden="true">
             </i><?php echo esc_html( get_the_modified_date() ); ?>
             </li>

    I have to add this php to meta as well, but I don’t know how to add it.

    <?php if ( 'my-meta' == $section ) { ?>
    	<li class="meta-my-meta"><i class="icon-layers"></i><?php esc_html_e( 'My Meta', 'oceanwp' ); ?></li>
    <?php } ?>

    if ( ‘my-meta’ == $section ) → true → run a next.
    if ( get_the_time(‘Y/m/d’) != get_the_modified_date(‘Y/m/d’) ) → true → show mod date.

    Could you help me with this?
    thank you.

    Thanks for the update @catlady053 . In the meta file, you see sections and this is the section for modified date:

    <?php c { ?>
    			<li class="meta-mod-date"<?php oceanwp_schema_markup( 'modified_date' ); ?>><span class="screen-reader-text"><?php esc_html_e( 'Post last modified:', 'oceanwp' ); ?></span><i class="<?php echo $theme_icons[ 'm_date' ][ $icon_t ]; ?>" aria-hidden="true"></i><?php echo esc_html( get_the_modified_date() ); ?></li>
    		<?php } ?>

    My suggestion would be to modify the if condition like this:
    if ( 'mod-date' === $section && 'mod-date'!='date' )

    This should get you the result you’re looking for. Please let me know if you need more assistance.

    Hello @catlady053

    It can be done this way but I will advise you not to make any changes, and I’ve added this to the features request list.

    and this would be the correct code.

    <?php if ( 'mod-date' === $section ) { ?>
                <?php if ( get_the_modified_date() != get_the_date() ) { ?>
                    <li class="meta-mod-date"<?php oceanwp_schema_markup( 'modified_date' ); ?>><span class="screen-reader-text"><?php esc_html_e( 'Post last modified:', 'oceanwp' ); ?></span><?php oceanwp_icon( 'm_date' ); ?><?php echo esc_html( get_the_modified_date() ); ?></li>
                <?php } ?>
            <?php } ?>
    Thread Starter catlady053

    (@catlady053)

    Thank you for your wonderful suggestions.

    @sansolo
    Yes, I was trying to just run the modified section if true.

    <?php if ( 'mod-date' === $section && get_the_modified_date() != get_the_date()) { ?>
                    <li class="meta-mod-date"<?php oceanwp_schema_markup( 'modified_date' ); ?>><span class="screen-reader-text"><?php esc_html_e( 'Post last modified:', 'oceanwp' ); ?></span><?php oceanwp_icon( 'm_date' ); ?><?php echo esc_html( get_the_modified_date() ); ?></li>
            <?php } ?>

    I was able to solve it with this syntax. Thank you.

    @abhikr781

    Your syntax also solved it. Thank you.
    If I get an error in the future, return it to the default.

    Both are helpful because I don’t need to add a new section to function.php and I can use the default modified.
    When I posted a new post, I thought it strange that the publish date and modified date would be displayed, so I’m glad that it was resolve it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Modified date hide or show’ is closed to new replies.