Using WordPress ‘get_real_file_to_edit()’ PHP function

The get_real_file_to_edit() WordPress PHP function retrieves the real filesystem path to a file within the admin area that is to be edited.

Usage

get_real_file_to_edit( $file );

Custom Example:

Input:

$file_path = get_real_file_to_edit( 'themes/my-theme/style.css' );
echo $file_path;

Output:

/home/user/public_html/wp-content/themes/my-theme/style.css

Parameters

  • $file (string) – Required. Filesystem path relative to the wp-content directory.

More information

See WordPress Developer Resources: get_real_file_to_edit()

Examples

Get the real path to a plugin file

Get the path to the main plugin file.

$plugin_file = 'plugins/my-plugin/my-plugin.php';
$real_path = get_real_file_to_edit( $plugin_file );
echo $real_path; // Outputs the real path to the plugin file

Retrieve the path to a theme’s functions.php

Get the path to the functions.php file of the current theme.

$current_theme = get_stylesheet_directory() . '/functions.php';
$real_path = get_real_file_to_edit( $current_theme );
echo $real_path; // Outputs the path to the theme's functions.php

Obtain the path to an uploaded image

Get the path to an uploaded image file.

$uploaded_image = 'uploads/2023/05/my-image.jpg';
$real_path = get_real_file_to_edit( $uploaded_image );
echo $real_path; // Outputs the real path to the uploaded image

Find the path to a custom file in the uploads directory

Get the real path to a custom file within the uploads directory.

$custom_file = 'uploads/custom-folder/my-custom-file.txt';
$real_path = get_real_file_to_edit( $custom_file );
echo $real_path; // Outputs the real path to the custom file

Access the path to a stylesheet in a child theme

Get the path to the style.css file in a child theme.

$child_theme = get_stylesheet_directory() . '/style.css';
$real_path = get_real_file_to_edit( $child_theme );
echo $real_path; // Outputs the path to the child theme's style.css