Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Robin Cornett

    (@littlerchicken)

    It looks like the social buttons aren’t showing on the autoloaded posts because of when the button location is determined in the output. I did some testing here and was able to get the buttons to show on autoloaded posts, but the buttons all referred to the first post instead of the autoloaded post. This is because WordPress considers this to be a singular post, but the autoload plugin turns it into something more like an archive.

    There may be a way to add a filter to the plugin to work around this, but it will take some thinking. I’ll update this thread if I find a workaround for you. Thanks–

    Plugin Author Robin Cornett

    (@littlerchicken)

    Actually, I take it back, I think you should be fine to try this code.

    In the plugin settings, change the Posts sharing button location to “Manual Placement”. Then add this code to your site, for example in your theme’s functions.php file or wherever you keep code snippets (please make sure files are backed up, practice safe coding, etc.):

    
    add_filter( 'the_content', 'prefix_add_scriptless_sharing_buttons', 100 );
    /**
     * Manually add sharing buttons to content.
     *
     * @param $content
     *
     * @return string
     */
    function prefix_add_scriptless_sharing_buttons( $content ) {
    	return $content . scriptlesssocialsharing_do_buttons();
    }
    

    The snippet above will add the buttons to the end of your content; you could swap the output and place the buttons at the beginning instead if you prefer. Hope this helps–

    Thread Starter politicske

    (@politicske)

    Thanks a lot! It worked. I use your buttons both at the beginning and at the end. Can the code be edited to support both?

    Plugin Author Robin Cornett

    (@littlerchicken)

    Sure, you can just change the value of what’s returned to the filer. Maybe something like:

    
    $buttons = scriptlesssocialsharing_do_buttons();
    
    return $buttons . $content . $buttons;
    

    This will amend the $content parameter and return it with buttons on either side. You might also consider setting it to be conditional on whether the plugin function exists, so if you deactivate the plugin for any reason, you site won’t be affected.

    Thread Starter politicske

    (@politicske)

    How would the final code look like?

    Plugin Author Robin Cornett

    (@littlerchicken)

    
    add_filter( 'the_content', 'prefix_add_scriptless_sharing_buttons', 100 );
    /**
     * Manually add sharing buttons to content.
     *
     * @param $content
     *
     * @return string
     */
    function prefix_add_scriptless_sharing_buttons( $content ) {
    	if ( ! function_exists( 'scriptlesssocialsharing_do_buttons' ) ) {
    		return $content;
    	}
    	$buttons = scriptlesssocialsharing_do_buttons();
    
    	return $buttons . $content . $buttons;
    }

    What this is doing is modifying the content of the post (passed to the function as $content). If the plugin is deactivated, the $content is returned unchanged. If the plugin is active, then we assign the HTML string to a variable and then return the $content with the variable both before and after it.

    Thread Starter politicske

    (@politicske)

    Thanks for the code. It is showing on pages though, including my custom homepage. How do I only show it in single posts? I am currently hiding it on pages with CSS. FYI, I have unticked the option to display the buttons and only selected manual option.

    • This reply was modified 6 years, 1 month ago by politicske.
    Plugin Author Robin Cornett

    (@littlerchicken)

    You need to use a conditional tag to determine if the content is rendering on a singular post.

    
    function prefix_add_scriptless_sharing_buttons( $content ) {
    	if ( ! is_singular( 'post' ) ) {
    		return $content;
    	}
    	if ( ! function_exists( 'scriptlesssocialsharing_do_buttons' ) ) {
    		return $content;
    	}
    	$buttons = scriptlesssocialsharing_do_buttons();
    
    	return $buttons . $content . $buttons;
    }

    Notice it follows the same pattern as the conditional to check if the function exists–if something is NOT true, then return the $content without modifying it.

    Thread Starter politicske

    (@politicske)

    Thanks. It worked!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Not showing in autoloaded posts’ is closed to new replies.