WP Discourse on Theme Lacking Site Editor

I’ve been happy using the WP Discourse plugin for our podcast WordPress site to connect to our Discourse Community. I stopped seeing the Discourse discussions sometime ago after the latest plugin update.

I might be wrong but it looks like now the way to add it to a template is via Full site Editor (?). I might look to change but am very happy with my Anders Noren Garfunkle theme. It’s single post template has a layout that puts comments in a tabbed display at the bottom of the post, outside the range of widgets.

I did consider just manually adding a Discourse block to all posts, but for now have made an adjustment that inserts the Discourse discussions using the HTML code. In my child theme, I comment out the standard WordPress comments template (we only allow comments via Discord), and check the post meta data for a discourse ID.

<?php //comments_template( '', true ); ?>

<?php
	$discourse_topic_id = get_post_meta( $post->ID, 'discourse_topic_id', 1 ); ?>
	
	<?php if ($discourse_topic_id) : ?>
	
		<div id="discourse-comments"></div>

			<script type="text/javascript">
			  DiscourseEmbed = { discourseUrl: 'https://connect.oeglobal.org/',
								 topicId: '<?php echo $discourse_topic_id?>' };
			
			  (function() {
				var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
				d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
				(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
			  })();
			</script>
	
<?php endif; ?>

It’s not as fancy a layout but works for now – see bottom of newest episode for example.

2 Likes

Hey @cogdog glad to hear how you’re using the plugin. You mentioned using blocks. Have you tried the WP Discourse Comment block?

1 Like

Yes, I use the WP Discourse Comment Block on another site where we have a FSE theme so it is in the template.

My issue is that my blog’s Garfunkel theme does not support it, and the comments space is built into the template. I am not full on with a block theme development- can I insert a block via PHP in the template? I am looking at things like Testing and Feedback for using block based template parts in classic themes – Make WordPress Themes but am not quite sure how to integrate an existing block.

The only other way I could see is adding the WP Discourse Comment Block at the bottom of every post, but I have 88 posts in the site already.

Ok, just rewinding a bit, let’s look at your issue again.

Do you mean you mean that:

  1. You just updated the WP Discourse plugin (and no anything else, i.e. not Wordpress, your theme or other plugins).
  2. Comment sync stopped working

Is that what happened?