WordPress Output all Custom Fields on Post or Page

Glenn Blog 0 Comments

Knowing what custom fields are outputting on your page or post / custom post can be very helpful when you are building up and/or testing dynamic content in WordPress. Here is a WordPress snippet that uses a shortcode to do just that:-

WordPress Output all Custom Fields on Post or Page PHP Code

Add the following to your child them’s functions.php file


add_shortcode( 'featureimage', 'shortcode_featureimage' );

// Show Custom Fields on Post Page Shortcode
function shortcode_showcf( $atts ){

$getPostCustom=get_post_custom();
foreach($getPostCustom as $name=>$value) {
        echo "<strong>".$name."</strong>"."  =>  ";
        foreach($value as $nameAr=>$valueAr) {
                echo "<br />     ";
                echo $nameAr."  =>  ";
                echo var_dump($valueAr);
        }
        echo "<br /><br />";
    }

}
add_shortcode( 'showcf', 'shortcode_showcf' );

Usage

Simply add the shortcode [showcf] to your post / custom post or page that you want to display all WordPress Custom fields on.

About the Author
Wordpress Output all Custom Fields on Post or Page WordPress Output all Custom Fields on Post or Page 0da77002febbfe28d15144a57bbcc2c9 s 180 d mm r g

Glenn

A highly experienced WordPress Web Developer, Front-end and Back-end Developer & New Media Specialist with extensive knowledge of a wide spectrum of technologies in the Development and Creative Industries built up over a number of years.

Leave a Reply

Your email address will not be published. Required fields are marked *