Created
October 5, 2024 07:54
-
-
Save pierrerocket/18fd50125e9c8a8b47980e211fb94598 to your computer and use it in GitHub Desktop.
print all post meta keys for current page site wide if in debug mode with query string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Display all meta keys for the current post if the 'debug_meta' query string is set | |
* and the site is in debug mode. | |
* | |
* This function is intended to be used on single post pages. It retrieves all meta keys for the | |
* current post and displays them inside a `<div>` element if the 'debug_meta' parameter is present | |
* in the URL and WP_DEBUG is set to true. The meta keys are outputted in a readable format for debugging purposes. | |
* | |
* @return void | |
*/ | |
function display_all_meta_keys_for_post() { | |
// Check if we're on a single post page, WP_DEBUG is enabled, and the query string 'debug_meta' is present | |
if (is_single() && defined('WP_DEBUG') && WP_DEBUG && isset($_GET['debug_meta'])) { | |
global $post; | |
$post_id = $post->ID; | |
$all_meta = get_post_meta($post_id); | |
if (!empty($all_meta)) { | |
echo '<div class="post-meta-keys"><h3>Meta Keys and Values:</h3>'; | |
echo '<pre>'; | |
print_r($all_meta); | |
echo '</pre>'; | |
echo '</div>'; | |
} else { | |
echo '<div class="post-meta-keys"><p>No meta keys found for this post.</p></div>'; | |
} | |
} | |
} | |
add_action('wp_footer', 'display_all_meta_keys_for_post'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment