Push Notifications in Flutter for New WordPress Posts (via Firebase & WP Plugin)

Push Notifications in Flutter for New WordPress Posts (via Firebase & WP Plugin)

June 20, 2025
WordPress push alert
To send push notifications in a Flutter app when new posts are published on a WordPress site using Firebase and a WordPress plugin, you’ll need to integrate Firebase Cloud Messaging (FCM) into your Flutter app and use a plugin on your WordPress site to handle the communication between the two. 

1. Firebase Setup:

  • Create a Firebase Project: Start by creating a new project in the Firebase console.
  • Register your app: Download the google-services.json (Android) or GoogleService-Info.plist (iOS) file and place it in the correct directory within your Flutter project.
  • Add Firebase dependencies: Include the firebase_messaging package in your pubspec.yaml file.
  • Initialize Firebase: Initialize Firebase within your Flutter app’s main function. 

2. Flutter App Integration:

  • Request notification permissions: Obtain user permission to receive notifications. 
  • Retrieve the FCM token: Get the device’s FCM registration token. You’ll need this token to send notifications to specific devices. 
  • Handle incoming messages: Implement logic to handle both foreground and background notifications. 

3. WordPress Plugin Setup:

  • Install a FCM plugin:
    Install a WordPress plugin designed for sending FCM notifications (e.g., wp_notify or similar). 

  • Configure the plugin:
    Configure the plugin with your Firebase credentials (API key, database URL, etc.). 

  • Connect Flutter app to the plugin:
    The plugin will likely provide an endpoint (e.g., /wp-json/fcm/pn/subscribe) to which your Flutter app can send a POST request to register the device’s FCM token. 

  • Trigger notifications on post publish:
    The plugin should automatically detect new posts and send a notification to all registered devices using FCM. 

4. Sending Notifications (from WordPress):

  • Triggered by new posts: When a new post is published, the WordPress plugin will send a notification to Firebase. 
  • Firebase sends to devices: Firebase then sends the notification to all registered devices that match the targeting criteria. 
  • Notification displayed: The Flutter app will receive the notification and display it to the user. 

Key Considerations:

  • Security:
    Secure your Firebase API keys and ensure proper authentication for your WordPress plugin. 

  • Error Handling:
    Implement robust error handling in both the Flutter app and WordPress plugin to manage potential issues during the notification process. 

  • Customization:
    Customize the notification content, including title, body, and potentially other data, based on the post content or user preferences. 

  • Testing:
    Thoroughly test the notification functionality in both foreground and background scenarios. 

  • User Experience:
    Provide a seamless experience for users to subscribe and unsubscribe from notifications.