ScreenshotNeo

BlogHow-to

ScreenshotMachine API Integration with WordPress Websites in India

Integrate ScreenshotMachine with WordPress using PHP and the WordPress HTTP API. Learn how to protect credentials, cache screenshots, handle errors, and assess India-specific considerations.

By the ScreenshotNeo team4 October 202610 min read

To integrate ScreenshotMachine with WordPress, keep its customer key and secret phrase on the server, build a URL-encoded request for the page to capture, and make that request with WordPress’s HTTP API. Check both the transport result and HTTP response before treating the response as an image. Cache the result with a transient if the screenshot does not need to update on every page view.

The same integration applies to a WordPress site hosted in India. The available documentation does not establish India-specific availability, pricing, tax treatment, data location, support terms, or performance. Confirm those details with ScreenshotMachine and test from your actual hosting environment before relying on them.

1. What you need

  • A ScreenshotMachine customer key and target page URL. The API accepts a GET request at https://api.screenshotmachine.com/. ScreenshotMachine API documentation
  • Optional capture settings, such as dimensions, format, cache limit, delay, and zoom. Check the live reference for current accepted values and limits.
  • A WordPress site where you can add a small custom plugin or theme code. A plugin is usually easier to maintain across theme changes.
  • For a public-facing integration, the account’s secret phrase and a server-side hash. ScreenshotMachine documents hash protection for calls made from public HTML. See its hash guidance.

Do not put the customer key or secret phrase in browser JavaScript, a shortcode attribute, or rendered page source. A visitor can inspect those values and reuse them.

2. Add credentials to WordPress

For a small, site-specific integration, define credentials in wp-config.php or inject them through your host’s protected configuration. Do not commit real credentials to a public repository.

// In wp-config.php, above the “stop editing” line.
define( 'SM_CUSTOMER_KEY', 'replace-with-your-customer-key' );
define( 'SM_SECRET_PHRASE', 'replace-with-your-secret-phrase' );

If administrators need to change credentials through the dashboard, build protected plugin settings with capability checks and nonce validation. Keep secrets out of settings pages’ public output and logs. The exact signature/hash construction depends on ScreenshotMachine’s current account configuration and documented rules; follow the vendor’s current instructions rather than guessing at a hash format.

3. Make a ScreenshotMachine request from WordPress

The following plugin example accepts an administrator-configured target URL, requests a PNG, checks errors and content type, and stores the image bytes in the uploads directory. It uses WordPress’s HTTP API rather than raw cURL, consistent with the WordPress guidance for external HTTP requests. WordPress HTTP API handbook

Create wp-content/plugins/sm-page-shot/sm-page-shot.php, add the code below, then activate “ScreenshotMachine Page Shot” in the Plugins screen. Set SM_TARGET_URL in wp-config.php to a page you are authorized to capture.

<?php
/**
 * Plugin Name: ScreenshotMachine Page Shot
 * Description: Captures a configured page with ScreenshotMachine and saves the image.
 * Version: 1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * Request a screenshot and save the returned image in uploads.
 * Run this from a controlled admin action or scheduled task, not on every page view.
 *
 * @return array|WP_Error File details or an error.
 */
function smwp_capture_page() {
    if ( ! defined( 'SM_CUSTOMER_KEY' ) || ! defined( 'SM_TARGET_URL' ) ) {
        return new WP_Error( 'smwp_missing_config', 'ScreenshotMachine key or target URL is not configured.' );
    }

    $target = esc_url_raw( SM_TARGET_URL );
    if ( ! $target || ! wp_http_validate_url( $target ) ) {
        return new WP_Error( 'smwp_invalid_url', 'The configured target URL is invalid.' );
    }

    $args = array(
        'key'       => SM_CUSTOMER_KEY,
        'url'       => $target,
        'dimension' => '1024x768',
        'format'    => 'png',
        // Add only options supported by the vendor's current API reference.
    );

    // If a secret phrase is configured, add the hash exactly as described by
    // ScreenshotMachine for the account. Do not expose the phrase to the browser.

    $api_url = add_query_arg( $args, 'https://api.screenshotmachine.com/' );
    $response = wp_remote_get( $api_url, array(
        'timeout'     => 60,
        'redirection' => 3,
        'headers'     => array( 'Accept' => 'image/png' ),
    ) );

    if ( is_wp_error( $response ) ) {
        return new WP_Error( 'smwp_transport_error', 'Screenshot request failed: ' . $response->get_error_message() );
    }

    $status       = wp_remote_retrieve_response_code( $response );
    $content_type = wp_remote_retrieve_header( $response, 'content-type' );
    $body         = wp_remote_retrieve_body( $response );

    if ( 200 !== $status ) {
        return new WP_Error( 'smwp_http_error', 'ScreenshotMachine returned HTTP ' . absint( $status ) . '.' );
    }
    if ( false === stripos( (string) $content_type, 'image/' ) ) {
        // Error bodies may be text or JSON. Avoid printing them to visitors.
        return new WP_Error( 'smwp_not_image', 'The API response was not an image. Check credentials, parameters, and vendor error details.' );
    }
    if ( '' === $body ) {
        return new WP_Error( 'smwp_empty_image', 'The API returned an empty response.' );
    }

    $upload = wp_upload_bits( 'screenshotmachine-' . gmdate( 'Ymd-His' ) . '.png', null, $body );
    if ( ! empty( $upload['error'] ) ) {
        return new WP_Error( 'smwp_save_error', $upload['error'] );
    }

    return $upload;
}

This example deliberately does not invent a hash algorithm or vendor error schema. Consult the API guide and the official PHP client README for the current secret-phrase/hash procedure and any additional options. The PHP client documentation describes generating a request URL and displaying or saving the resulting image.

Triggering the capture safely

Call smwp_capture_page() from an authenticated admin action with a nonce, a WP-CLI command, or a scheduled job. Avoid calling it directly from an unauthenticated page request: repeated visits could create unnecessary API calls and consume account quota. If you expose a shortcode, have it display a previously saved or cached image instead of triggering a new capture on every visitor request.

4. Display an existing saved screenshot

Once the capture has succeeded, render its URL with escaping. For example, after storing the returned upload URL in an option named smwp_last_image_url:

$image_url = get_option( 'smwp_last_image_url' );
if ( $image_url ) {
    echo '<img src="' . esc_url( $image_url ) . '" alt="Website screenshot" loading="lazy">';
}

Save the URL only after smwp_capture_page() returns a successful result. If capture fails, keep the previous image or show a neutral fallback; do not render the vendor’s error body as image markup.

5. Add caching and refresh behavior

Use a transient when the page can reuse a screenshot for a defined period. WordPress transients are time-limited cached values; their actual storage may be provided by the database or an object cache. WordPress Plugin Handbook

$cache_key = 'smwp_' . md5( $target . '|1024x768|png' );
$cached = get_transient( $cache_key );

if ( false === $cached ) {
    $result = smwp_capture_page();
    if ( is_wp_error( $result ) ) {
        // Log a sanitized diagnostic for administrators; retain any old image.
        return $result;
    }
    $cached = $result['url'];
    set_transient( $cache_key, $cached, 6 * HOUR_IN_SECONDS );
}

In production, adapt the capture function to return the saved URL and ensure the cache key includes every setting that changes the image: target URL, dimensions, format, delay, zoom, and relevant device or capture options. Choose a TTL based on how quickly the source page changes. Invalidate the transient when an administrator changes the target or settings. Do not assume ScreenshotMachine’s own cacheLimit and a WordPress transient have the same behavior: they are separate caching layers.

6. Choose the implementation path

Path Best fit Check before using
Custom plugin or site-specific code You need control of credentials, validation, error handling, storage, and refresh timing. Use capability checks for admin actions, validate inputs, escape output, and test upgrade behavior.
Shortcode plugin You need an editor-friendly embed and the plugin fits your use case. The WordPress.org directory has listed “JSM Screenshot Machine Shortcode,” but the listing alone does not establish present maintenance quality or compatibility. Check its current release, tested WordPress version, support activity, and how it handles credentials before installing. Directory listing
Official PHP client You prefer the vendor’s PHP wrapper for request construction. Review its current README and installation instructions; it supports Composer or manual download. Keep the secret phrase server-side. Repository

7. India-specific deployment considerations

The API and WordPress implementation sources describe general behavior, not special India operations. They do not verify whether ScreenshotMachine offers a particular billing currency, how taxes are handled, where capture data is processed, what support terms apply, or what response times an Indian host will see. Confirm these with the provider and the account’s current terms.

For deployment from India, test from the actual WordPress host, not only a laptop. Hosting region, DNS, outbound firewall rules, TLS configuration, and the target website’s own response can affect the request. Record response status and duration in server-side logs without recording API secrets or sensitive query parameters.

8. Security, reliability, performance, and cost

  • Validate the target: Prefer a fixed administrator-configured URL over arbitrary visitor input. If accepting a URL, validate the scheme and host, reject local/private network destinations where appropriate, and constrain allowed destinations to reduce server-side request forgery risk.
  • Escape output: Use esc_url() for an image URL and appropriate escaping for any text. WordPress’s plugin guidance emphasizes sanitizing and validating input and escaping output. WordPress common issues guidance
  • Handle failures: A successful WordPress HTTP transport does not guarantee a valid screenshot. Check HTTP status, content type, and nonempty body. Preserve a last-known-good image when refresh fails.
  • Avoid page-load capture: Capture in a scheduled/admin workflow and serve a cached image. This keeps the visitor page from waiting on an external request and avoids repeated calls.
  • Set a bounded timeout: Choose a timeout that fits the host and capture behavior; the example uses 60 seconds. A larger timeout can tie up PHP workers, while too small a timeout can fail on slow target pages.
  • Control storage: Saved image files use disk and backups. Define retention and cleanup for old captures, or cache only a reference when your serving requirements allow it.
  • Measure your own usage: The reviewed sources do not provide a price or India-specific cost figure. Check the current ScreenshotMachine account pricing and billing terms; account for capture volume, refresh frequency, and any storage or hosting costs.

9. Troubleshooting

Symptom Likely cause Fix
WP_Error from wp_remote_get() DNS, TLS, firewall, outbound network, or timeout issue between the host and API. Inspect the error in server logs, verify outbound HTTPS access from the host, and adjust the timeout only if the operation needs more time.
HTTP error or non-image response Invalid key, URL, option, or required hash; the response may contain a vendor error instead of image bytes. Check the account credentials and current API parameter documentation. Inspect response details privately, redacting credentials and sensitive URLs.
Hash-protected calls are ignored Secret phrase or hash does not match the current vendor rules, or the account requires a hash. Generate the hash on the server exactly as documented for the account. Never expose the secret phrase in the browser.
Screenshot is stale WordPress transient, vendor cache setting, or a stored image has not expired or been invalidated. Check both cache layers, include capture settings in the cache key, and clear/refresh on configuration changes.
Image is blank, incomplete, or too small The target page may load content late, rely on JavaScript, or need different dimensions, delay, zoom, or device settings. Adjust documented capture options and test on the actual target. Confirm the target itself is accessible to the screenshot service.
File save fails Uploads directory permissions, disk space, or filename handling problem. Check WordPress upload configuration and disk capacity; log the save error for administrators.
Works locally, fails on Indian hosting Hosting network policy, DNS, TLS certificate chain, or egress configuration differs. Test outbound API connectivity from the production host and ask the host about outbound HTTPS restrictions. This is an environment diagnosis, not evidence of India-wide service behavior.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. A single GET request captures a URL; the response can be PNG, JPEG, WebP, or PDF. Its cookie/consent banner handling and removal of 60+ known consent platforms, newsletter popups, and chat widgets can be switched off step by step. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP tools let Claude, Cursor, and other MCP clients take screenshots, inspect page information, and capture PDFs. Plans include 1,000 screenshots a month free with no card; paid plans start at $5 for 3,000.

cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo API documentation for request options. ScreenshotNeo also supports full-page and element captures, PDF settings, custom CSS and JavaScript, wait conditions, request blocking, signed links, asynchronous jobs, and bulk capture. Sign up for 1,000 free screenshots a month with no card; paid plans start at $5 for 3,000.

FAQ

Can I use ScreenshotMachine with a WordPress shortcode?

Yes, a shortcode plugin has been listed in the WordPress directory. Verify its current maintenance and compatibility before relying on it, and review how it protects credentials. A custom shortcode should render a cached image rather than initiate an external capture for every visitor.

Can I display the ScreenshotMachine API URL directly in an image tag?

The vendor documents generating a request URL for display as well as retrieving and saving an image. For a public page, keep credentials protected and follow its hash guidance; a server-side fetch and saved or cached image can keep secrets out of page source.

Does this integration guarantee a particular response time from India?

No. The reviewed sources do not establish India-specific latency, data location, billing terms, taxes, or support. Test your host and confirm current terms with the service provider.