Insert signup form in post

Has anybody actually gotten this working? Cause I’ve recommended it to many people who’ve asked about doing such a thing, with the caveat that I haven’t actually tried it out myself. Well, I just tried it out for a theme I’m finishing off, and it doesn’t actually work. I don’t recall where I got the code from, but nonetheless I (who doesn’t know any JS) did a bit of trial and error and actually got it working.

This the JS you’ll need, and replace the <div></div> with the code for the signup form or signup button or whatever else it is you’d like to insert.

<script>
    document.querySelectorAll(".non-member-insertion .subscribe-form-insertion").forEach((elem) => {
        elem.innerHTML = "<div></div>";
    });
</script>

Your snippet will look like such:

<div class="subscribe-form-insertion"></div>

And you’ll have to insert {{#if @member}} member-insertion{{else}} non-member-insertion{{/if}} around the content of the post/page, so something like this:

<div class='c-content{{#if @member}} member-insertion{{else}} non-member-insertion{{/if}}'>

Done.