I would like to add the post title to the entry_meta() function in the TwentySixteen Wordpress theme, in the template-tags.php file. I would like it to print before the author info. but after the avatar image.
basically just before the "screen-reader-text" span.
The function part:
if ( 'post' === get_post_type() ) {
$author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 205 );
printf( '<span class="byline"><span class="author vcard">%1$s<span class="screen-reader-text">%2$s </span> <a class="url fn n" href="%3$s">%4$s</a></span></span>',
get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ),
_x( 'Author', 'Used before post author name.', 'twentysixteen' ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
get_the_author()
);
}
Adding the_title() in the printf doesn't really work. So not sure how to approach this.
Thank you for anyone thats willing to help.
Figured it out.
added the get_the_title() and called it in with %5$s
if ( 'post' === get_post_type() ) {
$author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 205 );
printf( '<span class="byline"><span class="author vcard">%1$s<h1 class="entry-title">%5$s</h1><span class="screen-reader-text">%2$s </span> <a class="url fn n" href="%3$s">%4$s</a></span></span>',
get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ),
_x( 'Author', 'Used before post author name.', 'twentysixteen' ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
get_the_author(),
get_the_title()
);
}
Related
my problem is very simple but I am not familiar with PHP. My goal is to change the date format for the comments in my Wordpress blog from "26th of February 2021 at 12:23" to "43 minutes ago".
I also found a code snippet that does this for me, but it doesn't render the markup like the code which is provided by the theme itself.
This is the code provided by Astra:
printf(
'<div class="ast-comment-time ast-col-lg-12"><span class="timendate"><time datetime="%2$s">%3$s</time></span></div>',
esc_url( get_comment_link( $comment->comment_ID ) ),
esc_attr( get_comment_time( 'c' ) ),
/* translators: 1: date, 2: time */
esc_html( sprintf( __( '%1$s at %2$s', 'astra' ), get_comment_date(), get_comment_time() ) ),
);
This is the code I found:
printf( _x( '%1$s ago', '%2$s = human-readable time difference', 'wpdocs_textdomain' ),
human_time_diff( get_comment_time( 'U' ),
current_time( 'timestamp' )
);
I'd be more than happy if someone could help me with this since I don't know where to search for a solution anymore...
Thank you all!
This revision to your code may work as desired:
printf(
'<div class="ast-comment-time ast-col-lg-12">
<span class="timendate"><time datetime="%2$s">%3$s</time>
</span>
</div>',
esc_url( get_comment_link( $comment->comment_ID ) ),
esc_attr( get_comment_time( 'c' ) ),
esc_html( __( human_time_diff( get_comment_time( 'U' ) ) . ' ago', 'astra' ) )
);
I have some code
'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),
and I need to add html inside it. Basically I want to add
<span>Previous article</span>
before the title. How can I do this?
EDIT: The full function is
function mytheme_single_post_navigation() {
if ( ! is_singular( 'post' ) ) {
return;
}
if ( ! intval( mytheme_get_theme_mod( 'blog_single_navigation' ) ) ) {
return;
}
the_post_navigation( array(
/* translators: %s: title syntax. */
'prev_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),
/* translators: %s: title syntax. */
'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '%title' ),
) );
}
endif;
If you want to edit the wordpress post navigation in the single.php of your posts, you can use:
<span> <?php previous_post_link( '%link', '‹ Previous article' ); ?> </span>
<span> <?php next_post_link( '%link', 'Next article ›' ); ?> </span>
If you want to make it with setting 'next_text', you can also put your outpout in a string and use this:
<?php $next_post = '<span>Previous article</span>'; ?>
and then assign it to the 'next_text':
'next_text' => $next_post
If you read sprintf() function https://www.w3schools.com/php/func_string_sprintf.asp
you can add html tags with no problem. So it could also work with:
'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span> %title </span>' ),
But you do not want to have the title, so you don't actualy need this, if I got your question right.
EDIT:
If you want to show the span before the name of your post, you can use:
<?php previous_post_link( '%link', '<span>Previous article</span>'.' %title' ); ?>
With the dot . you are connecting the span element with the title.
So in your code, your the_post_navigation can look like:
the_post_navigation( array(
/* translators: %s: title syntax. */
'prev_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span>Previous article</span>'.' %title' ),
/* translators: %s: title syntax. */
'next_text' => sprintf( esc_html__( '%s', 'mytheme' ), '<span>Next article</span>'.' %title' ),
) );
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/
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;
How do I detach the link from the code below in my (child) functions.php? I want my dates to display as regular text.
<?php
if ( ! function_exists( 'twentyeleven_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
* Create your own twentyeleven_posted_on to override in a child theme
*
* #since Twenty Eleven 1.0
*/
function twentyeleven_posted_on() {
printf( __( '<time class="entry-date" datetime="%3$s" pubdate>%4$s</time><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
sprintf( esc_attr__( 'View all posts by %s', 'twentyeleven' ), get_the_author() ),
esc_html( get_the_author() )
);
}
endif;
?>
Thanks
are you just trying to get the date of a post? Use the function: the_date('y-m-d');
The string parameter denotes how you want the date to be displayed. You can learn more about this function at the Wordpress Codex