# WP link back to Discourse not showing when using custom code

**URL:** https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252
**Category:** WordPress
**Created:** [September 6, 2022, 3:40pm UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252 "2022-09-06T15:40:59Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Joep\_Kannegieter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joep_kannegieter/32/243065_2.png) [@Joep\_Kannegieter](https://meta.discourse.org/u/Joep_Kannegieter)
#### Post date: [September 6, 2022, 3:40pm UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/1 "2022-09-06T15:40:59Z")

</div>

Hi there,

I have an issue where on the WP side there is no link available to the Discourse forum. Just some answers on forum topics i found about this:

- All ’ Text Content’ fields are filled in in the WP admin → Plugin section.
- The sync runs; i can see the comments on both sides.
- The URL string is available in the \_postmeta db table

![image](https://global.discourse-cdn.com/meta/original/4X/f/4/3/f43ab19af47907bdd4287d2a54e5f71726473f45.png)

The comments section shows me Notices:

```plaintext
**Notice** : Trying to access array offset on value of type null in **/home/u48255p44743/domains/fxweb.snowfreakz.nl/public_html/wp-content/plugins/wp-discourse/lib/discourse-comment-formatter.php** on line **90**
 **Notice** : Trying to access array offset on value of type null in **/home/u48255p44743/domains/fxweb.snowfreakz.nl/public_html/wp-content/plugins/wp-discourse/lib/discourse-comment-formatter.php** on line **106**
 **Notice** : Trying to access array offset on value of type null in **/home/u48255p44743/domains/fxweb.snowfreakz.nl/public_html/wp-content/plugins/wp-discourse/lib/discourse-comment-formatter.php** on line **127**
 **Notice** : Trying to access array offset on value of type null in **/home/u48255p44743/domains/fxweb.snowfreakz.nl/public_html/wp-content/plugins/wp-discourse/lib/discourse-comment-formatter.php** on line **127**
 **Notice** : Trying to access array offset on value of type null in **/home/u48255p44743/domains/fxweb.snowfreakz.nl/public_html/wp-content/plugins/wp-discourse/lib/discourse-comment-formatter.php** on line **148**
 **Notice** : Trying to access array offset on value of type null in **/home/u48255p44743/domains/fxweb.snowfreakz.nl/public_html/wp-content/plugins/wp-discourse/lib/discourse-comment-formatter.php** on line **148**

```

Which are all related to the $URL in the file. I am calling the comments with:

```plaintext
<?php
global $post;
use WPDiscourse\Utilities\Utilities as DiscourseUtilities;
$discourse_comments = DiscourseUtilities::get_discourse_comments($post->ID);
echo $discourse_comments;
?>

```

Example URLs:  
[https://fxweb.snowfreakz.nl/nogmaals-een-test/](https://fxweb.snowfreakz.nl/nogmaals-een-test/)  
[https://fxdisc.snowfreakz.nl/t/nogmaals-een-test/23/2](https://fxdisc.snowfreakz.nl/t/nogmaals-een-test/23/2)

\<? ` echo get_post_meta( $post-\>ID, 'discourse_permalink', true ); ` ?\>

Placing the above direct call gives me no content back as link (found it in another topic)

Running Apache / PHP7.4 / WP 6.0.2  
After some hours troubleshooting i am out of options. Maybe someone has a clue !?  
Thanks in advance,

Joep

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [September 7, 2022, 6:47am UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/2 "2022-09-07T06:47:36Z")

</div>

Hey Joep,

If both of these things are true, then there is some other issue (non [WP Discourse](https://github.com/discourse/wp-discourse)) with your site.

> [@Joep\_Kannegieter](#):
>
> The URL string is available in the \_postmeta db table

> [@Joep\_Kannegieter](#):
>
> \<? ` echo get_post_meta( $post-\>ID, 'discourse_permalink', true ); ` ?\>
> 
> Placing the above direct call gives me no content back as link (found it in another topic)

Has this just started recently? What else has changed on your WP installation recently? Other plugins, themes, caching etc.

---

<div class="post-metadata">

### Author: ![Joep\_Kannegieter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joep_kannegieter/32/243065_2.png) [@Joep\_Kannegieter](https://meta.discourse.org/u/Joep_Kannegieter)
#### Post date: [September 7, 2022, 8:31am UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/3 "2022-09-07T08:31:12Z")

</div>

Hi Angus,

Thnx for reaching out … it’s a “fresh” Wordpress installation running Bricks template builder and just installed WPdiscourse for the connection. Besides mod\_headers server caching there are no other aggressive plugins altering any scripts.

Just added the direct PHP line again and … magically the URL is there. No idea what i did different.

```plaintext
<?php
global $post;
use WPDiscourse\Utilities\Utilities as DiscourseUtilities;
$discourse_comments = DiscourseUtilities::get_discourse_comments($post->ID);
echo $discourse_comments;

echo get_post_meta( $post->ID, 'discourse_permalink', true );
?>

```

 ![image](https://global.discourse-cdn.com/meta/original/4X/1/3/c/13c6210da7d96c7632ed1d644b4e46cc7dfc1495.png)

But i still have the Notices which relate to code lines where the URL should be constructed and the link after " Continue the discussion at" is not showing.

[https://fxweb.snowfreakz.nl/nogmaals-een-test/](https://fxweb.snowfreakz.nl/nogmaals-een-test/)

Joep

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [September 7, 2022, 8:53am UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/4 "2022-09-07T08:53:32Z")

</div>

Ok. Why are you loading the comments and permalink using your own custom code? The plugin handles this for you.

---

<div class="post-metadata">

### Author: ![Joep\_Kannegieter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joep_kannegieter/32/243065_2.png) [@Joep\_Kannegieter](https://meta.discourse.org/u/Joep_Kannegieter)
#### Post date: [September 7, 2022, 9:06am UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/5 "2022-09-07T09:06:39Z")

</div>

Hi,

When I include the “main” wordpress comments (which is a bricks template element) it shows the “normal WP comment form” which is not replaced by the Discourse reviews plugin. See the above URL; i changed the lay-out adding the WP comments below the Blog.

Backend settings

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/2/4/724b9d19d119c58222218418407edbf146aa002a.png)

Therefore i added the code manually as that showed the reviews and probably overrides any Bricks builder incompatibilities.

Joep

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [September 7, 2022, 10:08am UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/6 "2022-09-07T10:08:05Z")

</div>

Ok. There’s probably some kind of load priority issue with the template builder you’re using here. I’ll try and recreate it tomorrow. Sit tight.

---

<div class="post-metadata">

### Author: ![Joep\_Kannegieter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joep_kannegieter/32/243065_2.png) [@Joep\_Kannegieter](https://meta.discourse.org/u/Joep_Kannegieter)
#### Post date: [September 7, 2022, 10:11am UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/7 "2022-09-07T10:11:45Z")

</div>

Can i sent you the template builder for refference?

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [September 8, 2022, 12:49pm UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/8 "2022-09-08T12:49:25Z")

</div>

There will be various updates to the `get_discourse_comments` utility function in the next release (`2.4.6`), which is currently being prepared for release. The updated utility method signature will look like this

```plaintext
/**
* Get the Discourse comment HTML so that it can be displayed without loading the comments template.
*
* @param int $post_id The post ID to display the comments for.
* @param bool $perform_sync Determines whether a comment sync is maybe performed when loading comments.
* @param bool $force_sync Determines whether comment sync cache is bypassed when loading comments.
* @param string $comment_type Type of comment display.
*
* @return string
*/
public static function get_discourse_comments( $post_id, $perform_sync = true, $force_sync = false, $comment_type ) {

```

@Joep_Kannegieter This will have a few upshots for your case (and a few other cases):

- The comment display will work
- You’ll control the comment display type (i.e. all comments or comment link) programmatically
- You’ll control the comment cache programmatically

See further

[https://github.com/discourse/wp-discourse/pull/459](https://github.com/discourse/wp-discourse/pull/459)

---

<div class="post-metadata">

### Author: ![Joep\_Kannegieter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joep_kannegieter/32/243065_2.png) [@Joep\_Kannegieter](https://meta.discourse.org/u/Joep_Kannegieter)
#### Post date: [September 12, 2022, 6:46am UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/9 "2022-09-12T06:46:52Z")

</div>

Thnx! Gonna install and try it. Will report back the results.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [September 12, 2022, 7:44am UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/10 "2022-09-12T07:44:06Z")

</div>

It’s not released yet. Wait untill you see version `2.4.6` of the plugin ready for update in your Wordpress admin panel (I’ll ping you here too).

---

<div class="post-metadata">

### Author: ![Joep\_Kannegieter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joep_kannegieter/32/243065_2.png) [@Joep\_Kannegieter](https://meta.discourse.org/u/Joep_Kannegieter)
#### Post date: [October 16, 2022, 9:48am UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/11 "2022-10-16T09:48:39Z")

</div>

Hi Angus,

Coming back here; basically “i get it working” although not with the Bricks Builder template.  
When i switch to twentytwenty theme the Discourse integration shows below the blog post, replacing the Comments field

 ![image](https://global.discourse-cdn.com/meta/original/4X/f/6/1/f6113d0e91b6eb38322c7d799ccf8467d5e327c8.png)

When using Bricks Builder there is an element “Comments” which loads the WP comments; which is not replaced by the plugin. Neither programmatically called with:

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/6/f/46f50550a6233467ece520aa47ec173203817e49.png)

Programmatically called it throws the error:

> Error: Too few arguments to function WPDiscourse\Utilities\Utilities::get\_discourse\_comments(), 1 passed in /home/u43655p432443/domains/domain.nl/public\_html/wp-content/themes/bricks/includes/elements/code.php(159) : eval()'d code on line 4 and exactly 4 expected

So its Bricks related. Gonna ask the Bricks commmunity as well.

Joep

---

<div class="post-metadata">

### Author: ![Joep\_Kannegieter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joep_kannegieter/32/243065_2.png) [@Joep\_Kannegieter](https://meta.discourse.org/u/Joep_Kannegieter)
#### Post date: [October 16, 2022, 10:02am UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/12 "2022-10-16T10:02:20Z")

</div>

For now i just use PHP to call the comments in the template, using

```plaintext
<?php comments_template(); ?>

```

Which skips Bricks comments element ans uses core WP; that works.

 ![image](https://global.discourse-cdn.com/meta/original/4X/b/e/5/be5ae88b17560fb6683614eb58041436d661c02a.png)

Joep

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [October 17, 2022, 9:23am UTC](https://meta.discourse.org/t/wp-link-back-to-discourse-not-showing-when-using-custom-code/238252/13 "2022-10-17T09:23:58Z")

</div>

> [@Joep\_Kannegieter](#):
>
> Error: Too few arguments to function WPDiscourse\Utilities\Utilities::get\_discourse\_comments(), 1 passed in /home/u43655p432443/domains/domain.nl/public\_html/wp-content/themes/bricks/includes/elements/code.php(159) : eval()'d code on line 4 and exactly 4 expected

This error is telling you that your use of the utility function `get_discourse_comments` needs updating. Here’s an example of how you could use it.

```plaintext
global $post;
use WPDiscourse\Utilities\Utilities as DiscourseUtilities;
$discourse_comments = DiscourseUtilities::get_discourse_comments($post->ID, true, true, 'display-comments');
echo $discourse_comments;

```
