Show Last Updated Time instead of Published Time - php

I'm very new to Php. I want to show the Last Updated date instead of the Published time. Can someone help me? Thank you very much.
if ( ! function_exists( 'minimalistblogger_posted_on' ) ) :
function minimalistblogger_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
esc_html_x( 'Posted on %s', 'post date', 'minimalistblogger' ),
'' . $time_string . ''
);
$byline = sprintf(
esc_html_x( 'by %s', 'post author', 'minimalistblogger' ),
'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
);
echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
}
endif;

Ah! I found it!
Just use the
get_the_modified_time('F d, Y');
$modifiedtime = get_the_modified_time('F d, Y'); $posted_on = sprintf(
esc_html_x( 'Last modified on %s', 'post date', 'minimalistblogger'
), '' .
$modifiedtime . '' );
thank you :)

Related

Adding link in php Wordpress footer

I need some help in php. I need an hyperlink on the phrase inetio s. r.o.
The code is following:
if ( function_exists( 'get_the_privacy_policy_link' ) ) {
$footer_text = sprintf( _x( 'Copyright © %1$s %2$s. Všechna práva vyhrazena. %3$s', '1: Year, 2: Site Title with home URL, 3: Privacy Policy Link', '' ), esc_attr( date_i18n( __( 'Y', '' ) ) ), ''. esc_attr( get_bloginfo( 'inetio', 'display' ) ) . '', get_the_privacy_policy_link() ) . ' | ' . esc_html( $theme_data->get( 'inetio s. r. o.') ) . ' ' . esc_html__( 'vytvořilo inetio s. r. o.', 'solid-construction' ). ' <a target="_blank" href="'. esc_url( $theme_data->get( '' ) ) .'">'. esc_html( $theme_data->get( '' ) ) .'</a>';
}
Thanks for any help
boza
You can use it under WordPress built-in hook for this purpose.
add_action('wp_footer','dev_testing_func');
function dev_testing_func(){
/*Place your Code here*/
}

get category in posts, php

i try to write a simple code for php, which can show date,post autho and category but i can not show category. Where can i add it? this is code:
$posted_on = sprintf(
esc_html_x( 'Posted on111 %s', 'post date', 'sanse' ),
'' . $time_string . ''
);
$byline = sprintf(
esc_html_x( 'by %s', 'post author', 'sanse' ),
'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
);
Inside have_posts loop you can use get_the_category() function to display posts' categories.
$categories = get_the_category();
if ( ! empty( $categories ) ) {
echo '' . esc_html( $categories[0]->name ) . '';
}
https://developer.wordpress.org/reference/functions/get_the_category/

WordPress Footer Hook, PHP Editing Error

How can i edit this to just print out Copyright © 2017. All Rights Reserved. I keep getting an error on the last curly bracket when the second part of the function is removed and i can't figure it out.
*/
function nepalbuzz_get_content() {
$theme_data = wp_get_theme();
return sprintf( _x( 'Copyright © %1$s %2$s. All Rights Reserved', '1: Year, 2: Site Title with home URL', 'nepalbuzz' ), date_i18n( __( 'Y', 'nepalbuzz' ) ), ''. esc_attr( get_bloginfo( 'name', 'display' ) ) . '' ) . ' | ' . $theme_data->get( 'Name') . ' ' . esc_html__( 'by', 'nepalbuzz' ). ' <a target="_blank" href="'. $theme_data->get( 'AuthorURI' ) .'">'. $theme_data->get( 'Author' ) .'</a>';
}
I have edited to this:
function nepalbuzz_get_content() {
$theme_data = wp_get_theme();
return sprintf( _x( 'Copyright © %1$s %2$s. All Rights Reserved', '1: Year, 2: Site Title with home URL', 'nepalbuzz' ), date_i18n( __( 'Y', 'nepalbuzz' ) ), ''. esc_attr( get_bloginfo( 'name', 'display' ) ) . '' ) ; }
But I am still getting an unexpected syntax. Thanks for your time in advance!
You may just need to escape your double quotes.
function nepalbuzz_get_content() {
$theme_data = wp_get_theme();
return sprintf( _x( 'Copyright © %1$s %2$s. All Rights Reserved', '1: Year, 2: Site Title with home URL', 'nepalbuzz' ), date_i18n( __( 'Y', 'nepalbuzz' ) ), ''. esc_attr( get_bloginfo( 'name', 'display' ) ) . '' ) ; }

Removing Date/Time/Author Name in WordPress Posts

I am currently developing a WordPress site and would like to know what to change in the template-tags.php file to remove the date, time and author name.
Here is the code which I believe I need to change although each time I do I am greeted with the dreaded screen of death.
if ( ! function_exists( 'makewp005_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function makewp005_posted_on() {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
$time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
printf( __( '<span class="posted-on">%1$s</span> <span class="byline"> %2$s</span>', 'makewp005' ),
sprintf( '%2$s',
esc_url( get_permalink() ),
$time_string
),
sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_html( get_the_author() )
)
);
}
endif;
Thanks!
Why don't you use the CMS / API to remove them?
I believe this is the option to remove post info;
Larger: http://puu.sh/8rzux.png
So basically you want remove everything this function does.
if ( ! function_exists( 'makewp005_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function makewp005_posted_on() {}
endif;

comments link in shortcodes in Origin wordpress theme

I am using the Origin theme for wordpress and I am trying to customize the comments link right above the post. Right now it shows the number of comments and the text "comment" but I would like to only show the number (and show 0 when there are no comments). I found the relevant code in the theme > library > functions folder in shortcodes.php.
How do I edit this to only show the number of comments without the "comments" text for eg. "1" instead of "1 comment"?
This is the code currently:
function hybrid_entry_comments_link_shortcode( $attr ) {
$comments_link = '';
$number = doubleval( get_comments_number() );
$attr = shortcode_atts( array( 'zero' => __( 'Leave a comment', 'hybrid-core' ), 'one' => __( '%1$s comment', 'hybrid-core' ), 'more' => __( '%1$s comments', 'hybrid-core' ), 'css_class' => 'comments-link', 'none' => '', 'before' => '', 'after' => '' ), $attr );
if ( 0 == $number && !comments_open() && !pings_open() ) {
if ( $attr['none'] )
$comments_link = '<span class="' . esc_attr( $attr['css_class'] ) . '">' . sprintf( $attr['none'], number_format_i18n( $number ) ) . '</span>';
}
elseif ( 0 == $number )
$comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_permalink() . '#respond" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['zero'], number_format_i18n( $number ) ) . '</a>';
elseif ( 1 == $number )
$comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['one'], number_format_i18n( $number ) ) . '</a>';
elseif ( 1 < $number )
$comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['more'], number_format_i18n( $number ) ) . '</a>';
if ( $comments_link )
$comments_link = $attr['before'] . $comments_link . $attr['after'];
return $comments_link;
}
You just need to remove the word "comment" or "comments" in the relevant bits.
The line in question begins with $attr = shortcode_atts( ....
Here it is modified for you:
function hybrid_entry_comments_link_shortcode( $attr ) {
$comments_link = '';
$number = doubleval( get_comments_number() );
$attr = shortcode_atts( array( 'zero' => __( 'Leave a comment', 'hybrid-core' ), 'one' => __( '%1$s', 'hybrid-core' ), 'more' => __( '%1$s', 'hybrid-core' ), 'css_class' => 'comments-link', 'none' => '', 'before' => '', 'after' => '' ), $attr );
if ( 0 == $number && !comments_open() && !pings_open() ) {
if ( $attr['none'] )
$comments_link = '<span class="' . esc_attr( $attr['css_class'] ) . '">' . sprintf( $attr['none'], number_format_i18n( $number ) ) . '</span>';
}
elseif ( 0 == $number )
$comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_permalink() . '#respond" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['zero'], number_format_i18n( $number ) ) . '</a>';
elseif ( 1 == $number )
$comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['one'], number_format_i18n( $number ) ) . '</a>';
elseif ( 1 < $number )
$comments_link = '<a class="' . esc_attr( $attr['css_class'] ) . '" href="' . get_comments_link() . '" title="' . sprintf( esc_attr__( 'Comment on %1$s', 'hybrid-core' ), the_title_attribute( 'echo=0' ) ) . '">' . sprintf( $attr['more'], number_format_i18n( $number ) ) . '</a>';
if ( $comments_link )
$comments_link = $attr['before'] . $comments_link . $attr['after'];
return $comments_link;
}

Categories