Wordpress with PHP Everywhere

Sometimes you have to handle things in Wordpress that you can't find any plugin for.

In our case I had to visualize a list from a MySQL database and in another case I had to fetch data from another website.

In both cases I solved it with inserted PHP code which is executing and getting the info.

Plug-in
I have been using this plug-in, for several years, but there are no updates, and now also using the Gutenberg block editor, it was time to find another plug-in. 

After some Googling i found this plugin PHP Everywhere which can be used in both the old and the new editor.

It's just tested up to WP 5.5.3 but I'm using it on both 4.x.x and 5.6.2 and it works well.

Error handling
One major thing to consider is the error handling. Due to bad PHP code, and an upgrade by the web-host, some parts of our site stopped working. I solved this by simply adding 

<?php error_reporting(0); ?>

as the first row in my code which will encapsulate the error. In this way a potential error will not affect other parts of the site, and just produce "blank" information.

Test
To test the function just add a "PHP Everywhere" block or in the classic editor a shortcode "[php_everywhere]" and paste the code below.

Code example

<?php error_reporting(0); ?>
<?php
echo "Hello World ! <br>"; // Test
echo "Today is ".date("Y-m-d")."<br>";
$date = date("Y-m-d");
$time = date("H:i:s");

?>

<!DOCTYPE html>

<head>
<title>Today is ? </title>
</head>

<body>
<table>
<tbody>
<tr>
<td>
<li>Today is </li>
</td>
<td>
<?= $date ?>
</td>
</tr>
<tr>
<td>
<li>Time is </li>
</td>
<td>
<?php echo $time ?>
</td>
</tr>
</tbody>
</table>

</body>

</html>


Comments

  1. Fantastic read! Your passion for the subject really shines through. I appreciate the depth of research you’ve put into this. It’s inspiring!

    ReplyDelete

Post a Comment

Feel free to leave a comment ! ... but due to a lot of spam comments I have to moderate them. Will reply ASAP !

Popular post, last 30 days

Raspberry Pi OS Lite with GUI, RDP, VNC, Chromium

NetworkManager UI and access point, hotspot

iCloud drive sync, or mount, with a Linux, Ubuntu, device

Installing Ubuntu 24.04 or 24.10/25.04 on an old MacBook Air(2011)

Raspberry Pi 2, 3, 4, 5 USB SSD or USB drive boot

Clone the Raspberry boot disk

Signal K quick install, Raspberry Pi, Ubuntu

SeaTalk1 to NMEA 0183 converter, DIY

Volvo Penta NMEA 2000 Gateway

Waveshare CAN hat with Signal K & OpenPlotter