Home / Snippets / How to Add Disqus comment system to Laravel Application
How to Add Disqus comment system to Laravel Application cover

How to Add Disqus comment system to Laravel Application

1.7K

3 years ago

0 comments

In this short snippet, you will learn how to add the Disqus comments section to your Laravel project. The steps are quite straight forward and simple so let's get started.

Step 1: Register For Disqus Account


You will have to register for a Disqus account first and then visit your dashboard page.
Disqus Homepage

Step 2: Create a new Site


Once you have created an account then you can Create a New Site from the admin section. The steps for this is very straight forward so do make sure to fill in all the necessary credentials for your website.
Disqus Create new Site

Step 3: Get the Universal Code


Next, you will have to get the universal code from the Select Platform page.
Disqus Universal Code

The code will be as follows, do note that you need to copy your own code (the URL is different) for each comment section..
<div id="disqus_thread"></div>
<script>
    /**
    *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
    *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables    */
    /*
    var disqus_config = function () {
    this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
    this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
    };
    */
    (function() { // DON'T EDIT BELOW THIS LINE
    var d = document, s = d.createElement('script');
    s.src = 'https://YOUR-WEBSITE-HERE.disqus.com/embed.js';
    s.setAttribute('data-timestamp', +new Date());
    (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

Step 4: Make partial Blade File in Laravel


Once you have copy the code you will have to create a new partial and call it "disqus-comment.blade.php" and then paste the code in.
resources/views/partials/disqus-comment.blade.php
One important variable that you have to update is the "page.url" and "page.identifier". This will make your Disqus comment unique across different content.
this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; 
The value for this can be injected dynamically, do refer the code below.
this.page.url = '{{ url()->current() }}';
this.page.identifier = '{{ request()->path() }}'

Step 5: Include the Disqus to the page that you want to show it


Now you can include the Disqus partial to any of the pages you want to show the comment section. From your base file, you can write it like below.
@include('partials.disqus-comment')
Now do refresh the page that you have placed it on and you will be able to see the Disqus comment section.
Disqus Comment Section Preview
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this