- This topic has 13 replies, 5 voices, and was last updated 2 years, 11 months ago by
Tom.
-
AuthorPosts
-
February 8, 2020 at 1:09 pm #1159109
Carlo
I’d like to add the following shortcode to the below snippet code but not quite sure how to achieve this:
[editorskit display=”wordcount” before=”Reading Time: ” after=” min”]Im currently using this php snippet code to display metadata under my headings
add_filter( 'generate_post_author', '__return_false' ); add_filter( 'generate_show_comments', '__return_false' ); add_filter( 'generate_post_date_output', function( $date, $time_string ) { printf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ), get_avatar( get_the_author_meta( 'ID' ) ) ) ); if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { echo '<span class="comments-link">'; comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) ); echo '</span>'; } printf( '<span class="posted-on">%s</span>', $time_string ); }, 10, 2 );
and styled with the following CSS:
.byline img { width: 25px; height: 25px; border-radius: 50%; position: relative; vertical-align: middle; margin: 0 10px 0 0; } .byline, .comments-link, .posted-on { display: inline-block; } .comments-link, .posted-on { border-left: 1px solid #ddd; padding-left: 10px; margin-left: 10px; } .comments-link:before { display: none; } h2.entry-title { margin-bottom: 20px; }
February 8, 2020 at 1:50 pm #1159141Leo
StaffCustomer SupportHi there,
Try this format:
https://www.eprcreations.com/wordpress/add-shortcode-to-php-page/Let me know if this helps π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/February 8, 2020 at 10:51 pm #1159321Carlo
thanks Leo, yeah i did some searching and did see that code mentioned before, my problem is im not sure how to incorporate it into the code im using above. I keep getting errors when i add it so i guess im adding it in the wrong place?
<?php echo do_shortcode("[Shortcode]"); ?>
February 8, 2020 at 11:08 pm #1159333Carlo
Just some context in what the layout im trying to achieve:
HEADING
(author image) | author name | publish date | (shortcode = reading time)anyway to add on the shortcode to the end of the entry meta?
February 9, 2020 at 9:25 am #1159780Tom
Lead DeveloperLead DeveloperTry this:
echo do_shortcode( '[editorskit display="wordcount" before="Reading Time: " after=" min"]' );
Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentFebruary 11, 2020 at 12:08 am #1161393Carlo
Got it working, thanks Tom.
just one more thing, ive been playing around with the CSS to get them to stack nicely under each other in mobile view but just doesn’t look right.
Im trying to achieve the following layout in mobile. (with the solid border removed on .posted-on class. any quick tips here?
(author image) & author name
publish date
[shortcode = reading time]February 11, 2020 at 9:13 am #1162110Tom
Lead DeveloperLead DeveloperAny chance you can link me to the page so I can inspect the CSS/HTML?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentFebruary 16, 2020 at 12:13 am #1166755Carlo
Hi Tom, I updated the original post to include a link to the post.
i’ve added it to a test site until i work it out so i dont mess up my working site.also, ive added the “reading time shortcode” towards the bottom of this code, is this the right place to add it?
add_filter( 'generate_post_author', '__return_false' ); add_filter( 'generate_show_comments', '__return_false' ); add_filter( 'generate_post_date_output', function( $date, $time_string ) { printf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ), get_avatar( get_the_author_meta( 'ID' ) ) ) ); if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { echo '<span class="comments-link">'; comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) ); echo '</span>'; } printf( '<span class="posted-on">%s</span>', $time_string ); echo do_shortcode( '[editorskit display="wordcount" before="Reading Time: " after=" min"]' ); }, 10, 2 );
February 16, 2020 at 3:03 am #1166854David
StaffCustomer SupportHi there,
try this CSS for your mobile arrangement:
@media (max-width: 768px) { .entry-meta .posted-on, .editorskit-shortcode { display: block; border-left: 0; padding-left: 0; margin-left: 0; } }
And where you added the Shortcode looks fine.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/February 22, 2020 at 12:19 pm #1173852Carlo
Thanks David, worked like a charm
February 24, 2020 at 6:00 am #1175099David
StaffCustomer SupportYou’re welcome
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 7, 2020 at 5:46 am #1187773Bas
Hi, sorry to break into this thread but I have the same problem.
I can’t get the syntax right.
As of now, the second shortcode gets added into the first list item.What am I doing wrong?
add_filter( 'generate_post_author_output', 'add_to_end_of_meta' ); function add_to_end_of_meta( $output ) { echo $output . ' <ul class="reads-shares-meta"> <li class="post-reads-info">' . do_shortcode('[post-views]'); '</li> <li class="post-shares-info">' . do_shortcode('[social_warfare buttons="totals"]'); '</li> </ul> '; }
March 7, 2020 at 7:38 am #1187971Bas
And as always…. minutes after posting a question I find a working solution lol
add_filter( 'generate_post_author_output', 'add_to_end_of_meta' ); function add_to_end_of_meta( $output ) { echo $output . ' <ul class="reads-shares-meta"> <li class="post-reads-info">' . do_shortcode("[post-views]") . '</li> <li class="post-shares-info">' . do_shortcode('[social_warfare buttons="totals"]') . '</li> </ul> '; }
March 7, 2020 at 8:52 am #1188022Tom
Lead DeveloperLead DeveloperGlad you got it working! π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.