Credit and Legend position
-
Hello,
I found this nice pulg-in, but I’m searching a solution to put the credit under the legend of a media.
There is a solution ?
Regards.
-
Yes Display credit for featured images” is enabled but i don’t want it on home page, just in single page.
Here the code :
<?php get_header(); ?> <img src="<?php echo get_template_directory_uri(); ?>/img/pub/pub970_90.png" alt="pub"> <?php $post_id = 0; if (have_posts()): while (have_posts()) : the_post(); ?> <main id="contentbigone"> <?php $post_id = get_the_ID(); echo ' <div class="article round-all">'.afficherTheme($post_id, True, True).' <span class="titre-article">'.get_the_title().'</span><br /> <span class="chapeau-article">'.get_field( 'Accroche').'</span>'; //Image if ( has_post_thumbnail() ) { echo '<div class="media-credit-container">'; the_post_thumbnail('photo_une',['title' => get_the_title()] ); echo '</div>'; } echo ' <div class="infoslecture "> '.partager("Grey","smallmargintop").'<div> <span class="spaceimg aligneimgvert"><img src="'.get_template_directory_uri().'/img/icons/IconReading.png" alt="Temps de lecture"> '.tempsLecture().' <img src="'.get_template_directory_uri().'/img/icons/IconViews.png" alt="Nombre de vues"> '.do_shortcode( '[post-views]' ).'</span><br> <span class="spaceimg aligneimgvert"><img src="'.get_template_directory_uri().'/img/icons/IconAuthor.png" alt="Publication"> PUBLIé LE '.get_the_time('d/m/Y').' PAR '.get_the_author().'</span></div> </div> </div>'; ?> </main> <main id="contentone" > <?php echo ' <!-- article --> <article id="post-'.$post_id.'" class="article article-content round-all margintop">'; the_content(); echo '<div class="donnez-votre-avis round-all"><a href="'.get_the_permalink().'">DONNEZ VOTRE AVIS</a></div> </article> <!-- /article -->'; ?> </main> <?php endwhile; ?> <?php else: ?> <!-- article --> <article> <h1><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h1> </article> <!-- /article --> <?php endif; ?> <?php get_sidebar("single-one"); ?> <main id="contenttwo"> </main> <?php get_sidebar("single-two"); ?> <img src="<?php echo get_template_directory_uri(); ?>/img/pub/pub970_90.png" alt="pub"> <?php get_footer(); ?>
This looks fine. Can you please add the following snippet in your
functions.php
and check the log file if it is called?\add_filter( 'media_credit_post_thumbnail', functions( $output ) { \error_log("should display the post thumbnail credit"); return $output; } );
Sorry i don’t understand, error_log doesn’t work with :
define( ‘WP_DEBUG’, true );
define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_DEBUG_DISPLAY’, true);
@ini_set( ‘display_errors’, 1 );What do you mean “error_log does not work”? There is no output? Then either
in_the_loop()
returns false or thecredit_at_end
setting is set, oradd_media_credit_to_post_thumbnail
was unhooked frompost_thumbnail_html
– there is nothing else before the filter call.Hi,
error_log doesnt’t work, in my code if i put an error_log nothing is output or display.
So i can’t debug.
To display an image i use :the_post_thumbnail('photo_une',['title' => get_the_title()] );
Can i use a media credit function to display the caption ?
I put this to debug :
add_filter( 'media_credit_post_thumbnail', function( $output ) { error_log("should display the post thumbnail credit"); echo 'should display the post thumbnail credit'; return $output; } );
if you on go the page you will see this message before the image : should display the post thumbnail credit’
- This reply was modified 4 years, 3 months ago by delirium6.
I’m a bit confused. That page does display the credit?Oh. I misunderstood. You want the caption displayed as well. Media Credit itself does not have a feature for that (WordPress does not include the caption for featured images), but you can of course add a filter to
post_thumbnail_html
with a lower priority and add the caption yourself.- This reply was modified 4 years, 3 months ago by pepe.
No problem, yes i want the caption displayed on single page for featured images.
Could you be intesrested on this feature ? i can help you to add this feature on your plugin. Otherwise i will do as you tell me.Regards
Hi @pputzer ,
Are you instering in ?
Other subjet, you use the itemprop attributes in media credit, but it’s not compatible with W3C if the parent haven’t got the itemscope attribute.
See chapter 4.2 https://www.w3.org/TR/microdata/Regards
@delirium6 I’ll look in to the
itemprop
issue. Could be that the spec has changed since the feature was implemented. (To help keep track of things, please open a new thread if separate issue pops up.)Regarding displaying the caption, thanks for the offer, but I’ll have to decline. This is not standard WordPress behavior and I generally try to keep “feature creep” somewhat at bay so that the maintenance load stays somewhat manageable.
Ok, next time i will create a new Thread.
Ok no problem i understand your point of view.
But to solve my problem i’m a little loose.
You tell me to put a Hook on post_thumbnail_html.
You already have a hook on it with ‘add_media_credit_to_post_thumbnail’.
In this function there is :// Return early if we are not in the main loop or credits are to displayed at end of posts. if ( ! \in_the_loop() || ! empty( $this->settings['credit_at_end'] ) ) { return $html;
I’m not in this 2 cases because i got the credit but not the caption.
Where is your code which write the caption ? because i think it’s this function that i need to hook.Or can i use a shortcode ?
You can have multiple filters. The
$priority
parameter can be used to ensure execution in a deterministic order (the default priority is10
if the parameter is not specified).You can find the specification for the
post_thumbnail_html
filter (and the actual code of the function) in the WordPress API documentation forget_the_post_thumbnail()
.Sorry @pputzer , but i doesn’t know what to do in the hook to put the caption like in your plugin.
In another side, in my single page i tried to use this without success :
echo do_shortcode(‘[caption][media-credit standalone=false]’.get_the_post_thumbnail( $post_id, ‘photo_une’).'[/media-credit][/caption]‘);
It’s a good or bad way ?Regards
I put the final solution :
add_filter('post_thumbnail_html', 'caption_featured_images',11,5); function caption_featured_images( $html, $post_id, $post_thumbnail_id, $size, $attr ) { if(is_single( $post_id )) { if ( $post = get_post( $post_thumbnail_id ) ) { if ( $size = wp_get_attachment_image_src( $post->ID, $size ) ) $width = $size[1]; else $width = 0; $html='<div class="media-credit-container alignnone" '.($width!=0?'style="max-width:'.$width.'px;"':'').'>'.$html.'</div>'; $html = img_caption_shortcode( array( 'caption' => trim( "$post->post_content" ), 'class' => '', 'width' => $width, 'id' => 'attachment_'.$post_thumbnail_id ), $html ); } } return $html; }
Thanks for your help @pputzer
I am glad that you were able to fix this, @delirium6!
- The topic ‘Credit and Legend position’ is closed to new replies.