Here is an example of a simple WordPress plugin that uses the [phpinfo]
shortcode to display PHP information similar to what the phpinfo()
function does:
<?php /* Plugin Name: PHP Info Shortcode Description: Displays PHP information using the [phpinfo] shortcode. */ function phpinfo_shortcode_handler( $atts ) { // Build the HTML for the data $html = '<div>'; $html .= '<h3>PHP Information</h3>'; $html .= '<table>'; $html .= '<tr>'; $html .= '<th>Name</th>'; $html .= '<th>Value</th>'; $html .= '</tr>'; foreach ( get_defined_constants( true )['Core'] as $name => $value ) { $html .= '<tr>'; $html .= '<td>' . $name . '</td>'; $html .= '<td>' . $value . '</td>'; $html .= '</tr>'; } $html .= '</table>'; $html .= '</div>'; // Return the HTML return $html; } add_shortcode( 'phpinfo', 'phpinfo_shortcode_handler' );
This plugin defines a shortcode called [phpinfo]
that displays a table of PHP constants and their values.

When you include the [phpinfo]
shortcode in a post or page, the plugin will execute the phpinfo_shortcode_handler()
function to generate the HTML for the table of information.

To further customize the plugin you can add or remove constants from the table, or display different types of PHP information using other functions such as phpversion()
or php_uname()
.
Was this post helpful?
Let me know if you liked the post. That’s the only way I can improve. 🙂