Skip Navigation

[Resolved] shortcode for social share

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 6 replies, has 2 voices.

Last updated by Akhil 6 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1151082

Hi Nigel

this might not be for toolset but i am having issue with toolset related pages only.

i have big issue getting the social share plugin to work with toolset,
so i am testing 2 plugins., both have shortcodes : [social_warfare] , [easy_social_share] ,

this is my simple snippet ,

function my_social_share(){
  
  $string_with_shortcodes = "<div class='rss'>[social_warfare]</div>";
  echo do_shortcode($string_with_shortcodes);
  // [easy-social-share]  or [social_warfare]
}
add_shortcode('my_social_share', 'my_social_share');

i hope to manage the shortcode manually by editing the fn instead of editing every single layout template.

so my shortcode is [my_social_share]

it does load . but the problem is the it load at the most top position of the website,.
if i were to add the individual shortcode in the layout container directly, it load fine, same with other wp pages and post.

Do you see any issue with fn above ?
i have registered the shortcode at the toolset setting page.

#1151219

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Dee

With shortcodes you return the string to be output. You are echo-ing it, which means it gets printed to the screen when the code is encountered and not in the correct stage of building the page.

#1151910

Thanks

so its this then

function my_social_share(){
   
  $string_with_shortcodes = "<div class='rss'>[social_warfare]</div>";
  return do_shortcode($string_with_shortcodes);
  // [easy-social-share]  or [social_warfare]
}
add_shortcode('my_social_share', 'my_social_share');

#1152003

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Are you asking me or telling me?

#1152048

requesting your highness to confirm if its right 🙂

#1152102

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Well, registering a custom shortcode just to output another shortcode wrapped in a div seems a bit like overkill, but if you are inserting the original shortcode in a lot of places and want to save yourself the trouble of having to write that wrapper div manually each time, then I guess I see why.

As to whether you are doing it right, well, it looks okay, but the proof is in the pudding. Does it work?

#1152915

My issue is resolved now. Thank you!