- This topic has 7 replies, 3 voices, and was last updated 3 years, 3 months ago by Elvin.
-
AuthorPosts
-
December 28, 2020 at 4:46 am #1596605Danielle
Hi,
I would like to add my email signup embed form after a few paragraphes in every blog post via a hook. I currently have it in the bottom of my posts but I would like to see it within the first one-third of my blog posts instead.
Thanks!
December 28, 2020 at 6:46 am #1596725DavidStaffCustomer SupportHi there,
Hooks only exist in the Theme Templates – not within
the_content()
of you post or pages.
If you want to insert content within the post content then we recommend using the Ad Inserter plugin – it doesn’t just work with adverts, you can add any content you want including a shortcode for your form:December 28, 2020 at 12:05 pm #1597298DanielleIs there a way I can do this without a plugin?
December 28, 2020 at 1:40 pm #1597391DavidStaffCustomer SupportAside of manually adding them to the page, you would need a PHP Snippet like this:
add_filter( 'the_content', 'insert_content_after_paragraphs', 20 ); function insert_content_after_paragraphs( $content ) { $html = do_shortcode( '[your-shortcode]' ); if ( is_single() && ! is_admin() ) { return prefix_insert_after_paragraph( $html, 3, $content ); } return $content; } // Parent Function that makes the magic happen function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) { $closing_p = '</p>'; $paragraphs = explode( $closing_p, $content ); foreach ($paragraphs as $index => $paragraph) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } if ( $paragraph_id == $index + 1 ) { $paragraphs[$index] .= $insertion; } } return implode( '', $paragraphs ); }
The line:
$html = do_shortcode( '[your-shortcode]' );
you need to replace your-shorcode with the forms shortcode. However, i cannot say whether this will work correctly with all shortcodes.December 28, 2020 at 3:34 pm #1597477DanielleThanks for your help! I don’t have a shortcode for my Mailerlite forms, is there a way to implement the HTML code?
December 28, 2020 at 6:29 pm #1597578ElvinStaffCustomer SupportHi,
Thanks for your help! I don’t have a shortcode for my Mailerlite forms, is there a way to implement the HTML code?
Mailerlite plugin generates shortcode of something like this
[mailerlite_form form_id=1]
where1
is the ID of your form.But to directly answer the question:
Thanks for your help! I don’t have a shortcode for my Mailerlite forms, is there a way to implement the HTML code?
While we recommend sticking w/ the shortcode, you can do this by changing the line
$html = do_shortcode( '[your-shortcode]' );
to$html = 'your HTML code here'
but as David mentioned, its pretty uncertain if it will work properly.December 29, 2020 at 3:37 am #1597956DanielleThanks so much for your help! I managed to find the shortcode and it works like a charm!
December 29, 2020 at 8:47 pm #1598975ElvinStaffCustomer SupportNice one. No problem. 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.