WordPress is a popular and widely-used open-source content management system (CMS) and website building platform. It is used to create and manage websites of various types, from simple blogs to complex e-commerce websites and corporate sites. WordPress is known for its flexibility, ease of use, and extensive ecosystem of themes and plugins, which allow users to customize and extend their websites' functionality without needing to code from scratch.
If you have Discord server for your blog, you will want to notify others when there is a new post on your blog, but if you do it manually sometimes you forget to notify on your Discord server. In this post i will tell you how to send message automatically to your Discord sever with discord Webhooks.
Discord webhooks are a feature of the Discord messaging platform that allow external services to send messages to Discord text channels. They provide a way for developers to integrate Discord with other applications and services, enabling automated notifications and messages to be sent directly to Discord channels.
For first you need to create webhook in your Discord server, click the down arrow beside the server name and select Server Settings:
Click button New Webhook and webhook will be created, you can change webhook name and select which channel the webhook will send the message, and click Copy Webhook URL to get Webhook URL:
Now we can to the wordpress, in wordpress admin page hover cursor to Appearance in the side menu then another menu will appear next to it then select Theme File Editor:
On Theme Files in right select Themes Functions, then put this code at the bottom:
In the code above dont forget change YOUR_WEBHOOK_URL with your Webhook URL, if you want change message you can change variable value $postBody, you can see more param for message in https://discord.com/developers/docs/resources/webhook#execute-webhook
The sendWebhook function will be executed if the post status changes to publish, so try create new posting or change existing posts status become publish and webhook will send message to the channel you set previously and the result we be like this:
Thanks for reading this post, i hope this post can be useful, if you have question or feedback, you can send message in Contact or leave a comment.


0 Comments