Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add a shortcode to a blog post
- This topic has 8 replies, 2 voices, and was last updated 8 years, 6 months ago by Carla the Moose.
-
AuthorPosts
-
October 1, 2015 at 3:49 pm #167190Carla the MooseMember
I created a MailChimp widget to display on a specific page, within the entry content area. I'd like to add a paragraph after the signup form displays and figured shortcode would be the best way to do this.
How do I create shortcode for my widget? It's set to display at a particular hook on the subscribe page. If I want to place anywhere within the body text of that page, it seems I wouldn't need the hook.
Any suggestions on how to do this? I think I first need to activate shortcodes, or does the recent version of Genesis allow for that?
Thank you!!
October 1, 2015 at 4:43 pm #167200Carla the MooseMemberI found the shortcode page in the codex:
https://codex.wordpress.org/Shortcode_API
I added this outside of the widget function:
add_shortcode( 'mailchimp-shortcode', 'mailchimp' );
It works, and I didn't have to add anything to register shortcodes. But it's displaying after the text I wrote for the page instead of being inserted in between two paragraphs, and there's another subscribe form displaying, probably because of the hook I specified.
Still tinkering and learning.
October 1, 2015 at 4:50 pm #167201Carla the MooseMemberSince the shortcode will tell it where to go, I guess I don't need add_action or the conditional statement for it to display on a specific page. I removed that from the function, and it displays just fine, but it shows up at the top of the page and not between the two paragraphs.
So now I need to fiddle with placement. This is where I'm stuck. I'd love some guidance, thanks.
October 1, 2015 at 4:53 pm #167202Carla the MooseMemberI removed the hyphen in the shortcode name. If I'm understanding the codex correctly, numbers and underscores are okay, but not hyphens. It still didn't adjust the placement. Shouldn't the shortcode appear where I place it within the body of the page?
October 1, 2015 at 5:25 pm #167205Carla the MooseMemberI can't figure this out, so I've removed everything on the page except the shortcode and added the text to the widget.
I should be able to place the shortcode where I want it on the page, in between the two paragraphs. But I'm stuck. I'll have to come back to this another day and see if I can get it to work.
October 1, 2015 at 5:30 pm #167206Carla the MooseMemberAck, it's me again. There sure are a lot of coyote heads in this thread.
Here's the code. I noticed something that I didn't think to question. The before and after code ... not sure what it does. Could this be hanging up the shortcode and placing it first on the page?
// MAILCHIMP WIDGET genesis_register_sidebar( array( 'id' => 'mailchimp', 'name' => __( 'MailChimp widget', 'moose' ), 'description' => __( 'Adds a widget on the subscribe page.', 'moose' ), ) ); function mailchimp() { genesis_widget_area( 'mailchimp', array( 'before'=> '<div class="mailchimp widget-area">', 'after' => '</div>', ) ); } add_shortcode( 'chimpcode', 'mailchimp' );
October 1, 2015 at 10:15 pm #167216Carla the MooseMemberFrom what I've read, there doesn't seem to be a straightforward solution to getting a shortcode widget to neatly display when inserted in page text. So I added text to the widget and deal with it that way.
October 2, 2015 at 10:03 am #167240emmtreParticipantI'm using Genesis Extender on all sites. No brainer to add shortcodes.
October 2, 2015 at 11:55 am #167243Carla the MooseMemberI enjoyed learning how to add the shortcode myself, but I do remember reading about this plugin. Thanks for the reminder.
Using this plugin, are you able to insert shortcode between two paragraphs of text on a page or blog post and have it display correctly?
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.