Thread Starter
ricun
(@ricun)
EDIT: if I examine the elements with firebug the content in the scripts (url/title) are correct for every post, the problem is when I share/tweet
It’s not yet clear how you’re implementing AddToAny within the site. If you can provide a live example, or a Gist (or similar) of the HTML source, that could help folks here help you.
Thread Starter
ricun
(@ricun)
<div>
<?php
$args = array(
‘post_type’ => ‘my_post_type’,
‘posts_per_page’ => 3,
);
$query1 = new WP_Query($args);
while ($query1->have_posts()) : $query1->the_post();
$postarray = array(
‘title’ => get_the_title(),
‘share’ => get_the_permalink()
);
?>
<div class=”col-md-3″>
<div>
<?php the_content() ?>
<div class=”a2a_kit social-share”>
<i class=”fa fa-twitter”></i>
<i class=”fa fa-facebook”></i>
<span><p class=”share-text”>Share</p></span>
</div>
<script type=”text/javascript”>
a2a_config.linkname = <?php echo $postarray[‘title’] ?>;
a2a_config.linkurl = <?php echo $postarray[‘share’] ?>;
a2a.init(‘page’);
</script>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
</div>
That is one of the sections.
I have the <script type=”text/javascript” src=”//static.addtoany.com/menu/page.js”></script>
after the first script and is out of a repeating structure
Thread Starter
ricun
(@ricun)
EDIT: I have always used like this, and it works fine if there is only one instance like in the single.
In this unique case, I’d recommend using data-a2a- attributes to set the shared URL & title:
https://www.addtoany.com/buttons/customize/single_button_specific_page
<div class="a2a_kit a2a_kit_size_32 a2a_default_style social-share" data-a2a-url="https://example.com/page.html" data-a2a-title="Example Page">
<a class="a2a_button_twitter fa fa-twitter"></a>
<a class="a2a_button_facebook fa fa-facebook"></a>
<a class="a2a_dd share-text"></a>
</div>
If you’re using the plugin, it already loads page.js optimally, so there’s no need to load it again.
Thread Starter
ricun
(@ricun)
Fixed, the problem was my html structure:
My structure was
<div class="a2a_kit social-share">
<ul>
<li>
<a class="a2a_button_twitter"><i class="fa fa-twitter"></i></a>
</li>
<li>
<a class="a2a_button_facebook"><i class="fa fa-facebook"></i></a>
</li>
</ul>
</div>
I removed the ul/li
<div class="a2a_kit social-share">
<a class="a2a_button_twitter"><i class="fa fa-twitter"></i></a>
<a class="a2a_button_facebook"><i class="fa fa-facebook"></i></a>
</div>
It is working fine now.