WordPress.org

Ready to get started?Download WordPress

Forums

Share Buttons by AddToAny
[resolved] Custom button not sharing manual link (6 posts)

  1. Kevin
    Member
    Posted 5 months ago #

    Hi guys,

    On my homepage, I am trying to set up a manual share button which links to a specific post on my site. I included the following code in my homepage template:

    <?php if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) {
    ADDTOANY_SHARE_SAVE_KIT( array("linkname" => "Example Page", "linkurl" => "http://example.com/page.html") );
    } ?>

    The problem is that it is not providing a popup window to share the page provided in the "linkurl", but instead it is taking me here http://www.addtoany.com/share_save trying to link to the main website.

    I would provide a url to the website but its on a local server. Any ideas?

    https://wordpress.org/plugins/add-to-any/

  2. micropat
    Member
    Plugin Author

    Posted 5 months ago #

    Most likely AddToAny's required script is not loading. Where are you placing this code and in what theme?

  3. Kevin
    Member
    Posted 5 months ago #

    Hey thanks for responding,

    I cannot find any js in my plugin folder, maybe that has something to do with it? I downloaded it directly from the repository so don't know if that's it.

    I am placing this code within a loop that queries some fields from the most recent post of a custom post type. Here is the full code:

    <div id="top">
    			<header id="latest-message"><h2>LATEST MESSAGE</h2></header>
    			<?php 	$args = array(
    								'post_type' => 'messages',
    								'posts_per_page' => 1
    							);
    					$posts = get_posts( $args );
    					foreach ( $posts as $post ) : setup_postdata( $post );
    						$speaker = get_field( 'msg_speaker' );
    						$date = get_field( 'msg_date' );
    						$title = get_the_title();
    						$url = get_field( 'msg_url' );
    			?>
    			<div id="message-content">
    				<p class="info"><strong><?php echo $speaker; ?></strong>
    				<span class="date"><?php echo $date; ?></span>
    				</p>
    				<a href="<?php echo $url; ?>" class="title"><?php echo $title; ?></a></span>
    				<div id="social">
    					<a href="<?php echo $url; ?>" class="listen"><img src="<?php echo $template; ?>/images/home-social-bg.jpg" style="margin-left: -11px;" alt="LISTEN"></a>
    					<a href="<?php echo $url; ?>" download="<?php $title; ?>" class="download"><img src="<?php echo $template; ?>/images/home-social-bg.jpg" style="margin-left: -85px;" alt="DOWNLOAD"></a>
    					<?php if( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) {
    							ADDTOANY_SHARE_SAVE_KIT( array( 'linkname' => 'Example Page', 'linkurl' => 'http://example.com/page.html' ) );
    					} ?>
    				</div>
    			<?php	endforeach;
    			wp_reset_postdata(); ?>
    			</div>
    		</div>

    This is a custom theme based off of underscores. It has both wp_head() and wp_footer() where they belong. Any clue?

  4. micropat
    Member
    Plugin Author

    Posted 5 months ago #

    This works on other Underscores themes, so definitely keep troubleshooting your custom theme. First, make sure it's working on the default TwentySomething or default Underscores theme. Also, does the plugin's default sharing placement work with your custom theme?

    The asynchronously loaded JS is //static.addtoany.com/menu/page.js

    Viewing source, you should see a block of AddToAny code in your <head> for that.

    In your footer area, you should should see something like:

    wpa2a.targets=[
    {title:'Example Page',url:'http://example.com/page.html'};
    wpa2a.html_done=true;if(wpa2a.script_ready&&!wpa2a.done)wpa2a.init();wpa2a.script_load();
  5. Kevin
    Member
    Posted 4 months ago #

    I'm sorry, I only checked the files, the scripts actually are loading in the head and footer. The scripts were actually loading. After I saw that I explored the actual code and the issue had to do with the local cache variables. I have a custom upload directory, and when I checked the plugin correctly added an addtoany folder to that directory, but maybe that was causing issues? As soon as I turned off the use local cache option everything started working fine.

    How exactly does the caching option work and can you tell what was going wrong?

  6. micropat
    Member
    Plugin Author

    Posted 4 months ago #

    The old local script caching option was fixed in a recent release; however, most websites should not use this option because AddToAny's asynchronously-loaded script tends to load immediately in a visitor's browser thanks to AddToAny's client-side caching. With the local cache option enabled, visitors have to unnecessarily re-load AddToAny, which is slower on most websites. It's best to leave this one unchecked.

Reply

You must log in to post.

About this Plugin

About this Topic