I have a function that creates a div and uses an image from a toolset field as a background. Id like the function not to run on pages where the custom field is empty. My function below works great except when i add the conditional to it- then it doesnt appear to run under any circumstances.
php isnt my strong card- Do I have to test for wpcf-header-background-image set correctly?
// Add div.wrap outsideof header and give it a background image if one exixts in the field header-backround-image
Hello. Thank you for contacting the Toolset support.
Can you please share problem URL where I can see the header image is available as well as the URL of the page where header image is not available and share admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Minesh thanks the site is on my local host right now. I'll probably have it provisioned on a temporary domain next week sometime and could share access then. If you have any other thoughts in the meanwhile let me know
Please share details of problem URL and to what file you have added the code you shared.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I'm not sure why you created and added the code to sailing-heals.php file inside the plugins folder. However it was pure custom code which is beyond the scope of our support policy but as its was something bit easily done using the genesis hooks only.
I've adjusted and added the following code to "Custom Code" section offered by Toolset with the code snippet namely "toolset-custom-code":
=> hidden link
// Add div.wrap outsideof header and give it a background image if one exixts in the field header-backround-image
function sh_before_header_wrap() {
global $post;
$field = get_post_meta($post->ID,'wpcf-header-background-image',true);
$url = $field;
if(!empty($url)) {
echo "<div class='home-header_wrap' style='background-image: url(".$url.")'>";
}
}
add_action( 'genesis_before_header', 'sh_before_header_wrap' );
function sh_after_header_wrap() {
global $post;
$field = get_post_meta($post->ID,'wpcf-header-background-image',true);
$url = $field;
if(!empty($url)) {
echo '</div><!-- end .header_wrap -->';
}
}
add_action( 'genesis_after_header', 'sh_after_header_wrap' );