WordPress does not execute PHP pasted into a post. This guide explains how to run PHP with WPCode and display its output through a shortcode, using the site’s configured time zone as an example.

Before you begin

Back up the site and test on staging. Only use PHP you understand and trust: it runs on the server with WordPress’s permissions.

Create the snippet

  1. Open Plugins > Add New Plugin, search for WPCode, check compatibility, then install and activate it.

    Install and activate the plugin.

  2. Open Code Snippets > Add Snippet and choose the custom-code option.

     Add Your Custom Code

  3. Name it Show site time zone and choose PHP Snippet.

    Code Type

  4. Enter this code without an opening <?php tag:

    echo esc_html( wp_timezone_string() );
  5. Under Insertion, choose Shortcode.

  6. Activate the snippet and select Save Snippet or Update.

    Shortcode

Display the output

Copy the generated shortcode into a Shortcode block in the required post or page.

Shortcode

Save and check that its output matches Settings > General.

For automatic execution, choose Auto Insert instead and configure its location and conditions. Automatic and shortcode insertion are alternative modes; choose the mode needed for the snippet.