Displaying Custom Fields on Post with Genesis Child Theme

I have tried everything to get Custom Fields to display on my posts using a Child Theme of the Genesis theme framework. I have tried to follow every tutorial I could find relating to it but still I can’t get my Custom Fields to show on my posts!

The simplest looking solution I have been trying is using Brad Daltons instructions (I have tried many other methods) and adding the following to my functions file:

Read More
add_action( 'genesis_after_post_title', 'custom_field_before_content' );
/**
* @author Brad Dalton - WP Sites
* @link http://wp.me/p1lTu0-9WF
*/
function custom_field_before_content() {
if(is_page() || is_single() ) {
genesis_custom_field('instrument');
}
}

I have then added the custom field in my posts. I have tried adding the custom field with Advanced Custom Fields which shows perfectly in the admin but not on the post on my site.

Does anyone know what I am doing wrong to get this to output or a different method that might work for me. I done this no problem with different themes but using the Genesis theme framework I can’t get this to work – have been at it for two days!

Thanks,

Ciarán

Related posts

3 comments

  1. How about instead of genesis_custom_field('instrument'); use: echo genesis_get_custom_field('instrument');

    Plus the genesis_after_post_title action hook is deprecated since 1.7.0 and you should use genesis_entry_header with correct priorities. For more information please use the reference links below.

    Reference:

  2. Here is my solution for a Custom Post Type:

    Add this to functions.php. (Or, if you created a template for your custom post type like I did, such as single-instrument.php, add it to that instead of functions.php)

    // Display Advanced Custom Fields
    add_action('genesis_entry_header', 'type_of_instrument');
    
    function type_of_attorney() {
    if ( is_singular('profile') && genesis_get_custom_field('type_of_instrument') )
    echo '<hr /><div id="type_of_instrument">Title: '. genesis_get_custom_field('type_of_instrument') .'</div>';
    }
    

    This is assuming that you named your field ‘type_of_instrument’ in Advanced Custom Fields. Use whatever name you actually gave the field. You’ll have to adjust the code for multiple fields. It also creates a div around the field for easier styling.

    If you are not using a Custom Post Type, you would want to replace is_singular('profile'). My guess is with is_single but don’t quote me. If not try if(is_page() || is_single() ) as used in the code you submitted in your question.

    Hope that helps!

  3. Good question Ciarán. I, too, was stuck trying to display custom fields in Genesis. This thread got me unstuck. And along the way I discovered that it is possible to take these ideas even farther.

    For example, I have found it helpful to use the Advanced Custom Fields plugin to create landing pages in WordPress. I can add as many WYSIWYG fields as I need in the page and edit them all separately.

    To display the fields in Genesis, I use a variation of the code given previously by Borek and user55013. In the code below, I have added div tags so that I can format each field separately with CSS:

    add_action( 'genesis_after_content', 'display_custom_fields' );
    function display_custom_fields() {
        if( is_page_template( 'page_landing.php') ) {
            printf( '<div class="landing-part-one">%s</div>', get_field('landing_part_one') );
            printf( '<div class="landing-part-two">%s</div>', get_field('landing_part_two') );
            printf( '<div class="landing-part-three">%s</div>', get_field('landing_part_three') );
            printf( '<div class="landing-part-four">%s</div>', get_field('landing_part_four') );
        }
    }
    

    Meanwhile, back in the options panel of the field group editor of Advanced Custom Fields, I have positioned the custom WYSIWYG fields “High (after title)” and I have hidden the content editor. This produces a clean editing space for the custom fields, which appear in the page editor as though they were native to WordPress. And in the location rules, I have set the field group to display only for the landing page template.

    And though I originally tried ‘genesis_get_custom_fields()’ to display the fields in this function, it stripped all the <p> tags from the field. The output was a run-on paragraph. The Advanced Custom Fields function get_field() works better.

    Along the way I also learned the difference between ‘genesis_custom_fields()’ and ‘genesis_get_custom_fields()’. The first echoes the field directly. The second returns the contents of the field as a string.

    If you’re using Advanced Custom Fields to output images, this thread might be of use.

    I hope it helps 🙂

Comments are closed.