• Resolved tangobango

    (@tangobango)


    I’m trying to do a simple (I thought) filtering of the content to add the subscription form after the content.

    What I’m getting is the form twice: before the header and then again before the content. But I don’t get it after the content.

    Here’s what I’m doing:

    function obia_add_email_subscribers($content) {
    	if( is_singular() && is_main_query() ) {
    		$new_content = es_subbox($namefield = "YES", $desc = "", $group = "Public");
    		$content .= $new_content;
    	}
    	return $content;
    }
    add_filter('the_content', 'obia_add_email_subscribers');

    Where is my mistake?

    Thanks.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • @tangobango

    Apologies for the delayed response.
    I’m still unclear on how you wish to form the subscription with content filtration.
    You may simply display the box in the widgets section of your page.
    Do let me know your views on the same.

    Thread Starter tangobango

    (@tangobango)

    @prathameshp

    Thanks for the reply.

    I don’t want the subscription form in a widget area, but below the main content on each post, appended to the body of the post.

    If I use the approach I indicated in my first question, I can add any text/html I want to the bottom of the content with $content .= $new_content. But I can’t get the subscription form to show up correctly. The problem likely is related to the output of the es_subbox function.

    It’s really baffling that the filtering makes it show up twice in the wrong places. That shows, at least, that the html for the form is being created.

    Does this make sense?

    Thread Starter tangobango

    (@tangobango)

    In case someone else has this problem. here’s what to do:

    In your function that creates the filter, use

    do_shortcode( ' [email-subscribers namefield="NO" desc="" group="Public"] ' )

    rather than

    es_subbox($namefield = "YES", $desc = "", $group = "Public")

    so you end up with a function like this:

    function obia_output_email_subscribers_after_content( $content ) {
        if(( is_single() || is_page('read-from-the-beginning')) && is_main_query() ) {
            $output = '<div class="email-subscription-box">';
            $output .= '<p class="email-subscription-box-title">Like What You Are Reading?</p>';
            $output .= '<p class="email-subscription-box-copy">Join us and receive new posts by email.</p>';
            $output .= do_shortcode( ' [email-subscribers namefield="NO" desc="" group="Public"] ' );
            $output .= "<p class='email-subscription-box-disclaimer'>Unsubscribe anytime. No spam guarantee. We don't share our list.";
            $output .= '</div>';
            $content .= $output;
    		}
            return $content;
    }
    add_filter( 'the_content', 'obia_output_email_subscribers_after_content' );
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Add form via filtering the_content’ is closed to new replies.