I attempt to add addtoany shortcode in my customized loop web page however the shared hyperlink stays all the time the identical for every posts within the loop.
<?php
world $publish;
echo do_shortcode('[addtoany url="' . the_permalink() . '" title="' . the_title() . '"]')
?>
I additionally tried with get_permalink()
, get_permalink($post->ID)
, get_the_permalink()
… however nothing works. It ought to work like this, in accordance the official documentation.
I do not perceive why :/
EDIT
Right here is the complete perform:
<?php
add_filter( 'generate_do_template_part', perform( $do ) {
if ( is_archive() || is_search() ) {
return false;
}
return $do;
});
add_action( 'generate_before_do_template_part', perform() {
world $publish;
if ( is_archive() || is_search() ) : ?>
<article <?php post_class(); ?>>
<div class="inside-article sf-result">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="sfr-inner">
<div><?php if ( has_post_thumbnail() ) { ?><div class="sfr-thumb"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail("medium") ?></a></div><?php } ?></div>
<div><p><?php the_excerpt(); ?></p></div>
<div class="sfr-inner-bottom">
<span class="mdi mdi-share"></span><!-- share icon -->
<div class="sfr-share-box"><?php echo do_shortcode('[addtoany url="' . get_the_permalink() . '" title="' . get_the_title() . '"]') ?></div><!-- opens by a click on with a jQuery perform -->
</div>
</div>
</div>
</article>
<?php endif;
}); ?>
With this perform, I override the loop in archive and search web page generate by GeneratePress theme (and searchanfilter plugin). I get the right permalink for the title, the thumbanil and the excerpt with out downside, however not inside this shortcode.