I’ve written a custom function which works with the native WordPress custom fields function but I need it to work with the Advanced Custom Fields plugin.
I have created the custom field and meta box using the plugin and added the function to my child theme’s functions.php
file.
I am using the field name (demo_field) for the meta box in the custom function but the meta box does not hook in to the function.
add_action( 'genesis_after_post_content', 'custom_field_before_content' );
function custom_field_before_content() {
if(is_single() ) {
genesis_custom_field('demo_field');
}
}
What am I doing wrong?
Ok i fixed that but it doesn’t return the image even though i configured the settings to return value for the image object.
It displays the HTML for the image.
add_action( 'genesis_after_post_title', 'custom_field_before_content' );
function custom_field_before_content() {
if(is_single() ) {
the_field('second_image');
}
}
Here’s what it displays:
32538, , second feature image, , , /wp-content/uploads/2013/06/second-feature-image.png, 600, 300, Array
Here’s the final solution i worked out myself which i tested and works with Genesis only. You can change the hook if using another theme with hooks.
add_action( 'genesis_after_post_title', 'custom_field_before_content' );
function custom_field_before_content() {
if(is_single() )
if( get_field('second_image') ):
?><img src="https://wordpress.stackexchange.com/questions/101928/<?php the_field("second_image'); ?>" alt="" /><?php
endif;
}
The code comes from the ACF website.http://www.advancedcustomfields.com/resources/field-types/image/