Home › Forums › Pro Support › WPSP Social Icons (class="wpsp-social") shortcode?
- This topic has 6 replies, 2 voices, and was last updated 6 years, 6 months ago by
Tom.
-
AuthorPosts
-
November 24, 2016 at 9:34 am #1091
Sebastian
ParticipantHi Tom, I would like to place the WPSP Social Icons (class=”wpsp-social”) in each post. Is there a Shortcode for this?
Regards,
SebastianNovember 24, 2016 at 12:55 pm #1093Tom
KeymasterHi there,
You mean in the single post itself (not WPSP)?
Typically this plugin doesn’t add/modify the theme you’re using, it only affects the list of posts.
However, you could try making a shortcode out of this function:
if ( $social_sharing && function_exists( 'wpsp_social_sharing' ) ) : echo wpsp_social_sharing( get_the_ID(), $twitter = true, $facebook = true, $googleplus = true, $pinterest = true, $love = true, $social_sharing_alignment = 'left' ); wp_enqueue_script( 'wpsp-love-it' ); endif;
November 25, 2016 at 1:56 am #1101Sebastian
ParticipantHi Tom, yes exactly. I want to take social_sharing from WPSP and place it in a single post.
I’ve tried, it does not work. I’m not a good coder, sorry 🙁 can you help me please?
What am I doing wrong?
add_shortcode( 'wpsp_social_sharing', 'wpsp_social_sharing_shortcode' ); function wpsp_social_sharing_shortcode() { if ( $social_sharing && function_exists( 'wpsp_social_sharing' ) ) : echo wpsp_social_sharing( get_the_ID(), $twitter = true, $facebook = true, $googleplus = true, $pinterest = true, $love = true, $social_sharing_alignment = 'left' ); wp_enqueue_script( 'wpsp-love-it' ); endif; }
November 27, 2016 at 3:48 am #1116Sebastian
ParticipantI tried and it worked. But I do not understand one thing.
get_the_title() is output at the exact location, where I placed the shortcode [xxx_wpsp_social_sharing] in the post content. The social icons, however, are at the top left on the website. Why?
function wpsp_social_sharing_shortcode() { return get_the_title() . wpsp_social_sharing( get_the_ID(), $twitter = true, $facebook = true, $googleplus = true, $pinterest = true, $love = true ); wp_enqueue_script( 'wpsp-love-it' ); } add_shortcode( 'xxx_wpsp_social_sharing', 'wpsp_social_sharing_shortcode' );
November 27, 2016 at 12:26 pm #1123Tom
KeymasterHmm, you could try this:
function wpsp_social_sharing_shortcode() { ob_start(); echo get_the_title() . wpsp_social_sharing( get_the_ID(), $twitter = true, $facebook = true, $googleplus = true, $pinterest = true, $love = true ); wp_enqueue_script( 'wpsp-love-it' ); $output_string = ob_get_contents(); ob_end_clean(); return $output_string; } add_shortcode( 'xxx_wpsp_social_sharing', 'wpsp_social_sharing_shortcode' );
November 28, 2016 at 12:11 am #1129Sebastian
ParticipantTom, you’re a genius, thanks 🙂
November 28, 2016 at 1:03 am #1130Tom
KeymasterYou’re welcome! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.