I'm new to PHP code and am trying to find a way to display 3 lines from the version.php
file within WordPress without having to download the file; look into it and move on - this is what I have come up with so far, but does not seem to be working. I'm sure I'm doing something wrong here and would greatly appreciate some help.
<?php
$version = "wp-includes/version.php";
$all_lines = file($version);
echo $all_lines[16];
echo $all_lines[23];
echo $all_lines[37];
?>
To be able to see specific version numbers on your frontend its best to create a shortcode and use that shortcode to output.
Add the below code in functions.php
file.
function bks_show_versions( $atts ) {
global $wpdb;
$wordpress = $GLOBALS['wp_version'];
$php_version = phpversion();
$mysql_version = $wpdb->db_server_info();
return sprintf("<pre> wordpress version : %s | php version: %s | mysql version : %s </pre>", $wordpress, $php_version, $mysql_version);
}
add_shortcode( 'show_versions', 'bks_show_versions' );
This basically will fetch all the values and print them on the screen.
<pre> wordpress version : 5.7 | php version: 7.4.16 | mysql version : 5.7.24 </pre>
Now, at whichever page you want it to print,edit that page and add [show_versions]
on that page. Now view that page. You should be able to see.
You can use this article to understand how to add shortcode to a page.
The shortcode you have to add is : [show_versions]