- This topic has 3 replies, 2 voices, and was last updated 8 years, 1 month ago by
Tom.
-
AuthorPosts
-
August 10, 2017 at 10:09 am #363228
Adrian
Hi!
I have the “Page Header” add-on enabled. I have created a header to the posts like this:
<h1>{{post_title}}</h1> {{post_author}} {{post_date}}
All perfect. Now I need to remove the {{post_author}} and {{post_date}} links, plus I have to add the author’s avatar, but when I using the ‘generate_post_author_output’ filter does not affect it.
I have tried different ways even with one of your examples:
add_filter( 'generate_post_author_output', 'tu_add_author_gravatar' ); function tu_add_author_gravatar() { printf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s %5$s<a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>', __( 'by','generatepress'), 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' ) ) ) ); }
Can not filters be applied when using the “Page Header” add-on?
Then, since the filter did not work for me, I tried to put it in the following way:
add_action( 'generate_after_entry_title','arj_add_custom_meta'); function arj_add_custom_meta(){ if (is_singular('post')) { global $post; $author_id = $post->post_author; ?> <div class="foto-autor"> <?php // Avatar del usuario del post. echo get_avatar( $author_id ); ?> </div> <p class="autor-post"><?php echo get_the_author_meta( 'nickname', $author_id ); ?></p> <time datetime="<?php the_time('Y-m-d'); ?>"><?php the_time('d F Y'); ?></time> <?php } }
But having the add-on activated, what I add to this filter appears inside the article, not inside the header.
Thanks in advance!
August 10, 2017 at 11:16 am #363312Tom
Lead DeveloperLead DeveloperThe Page Header add-on uses a very stripped down version of those elements – it doesn’t include all the HTML that’s included in the regular meta.
However, you can create a shortcode, and add that into the page header:
function tu_custom_author_meta() { ob_start(); global $post; $author_id = $post->post_author; ?> <div class="foto-autor"> <?php // Avatar del usuario del post. echo get_avatar( $author_id ); ?> </div> <p class="autor-post"><?php echo get_the_author_meta( 'nickname', $author_id ); ?></p> <time datetime="<?php the_time('Y-m-d'); ?>"><?php the_time('d F Y'); ?></time> <?php return ob_get_clean(); } add_shortcode( 'author_meta','tu_custom_author_meta' );
Then just use
[author_meta]
in the Page Header content.August 10, 2017 at 11:52 am #363358Adrian
Many thanks Tom!!
It works perfect, I thought you could not use shortcodes in that part!
And thanks for adding “ob_start()” I had not noticed!
August 11, 2017 at 12:38 am #363706Tom
Lead DeveloperLead DeveloperYou’re welcome! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.