- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hi,
Hoping someone can assist with how I would go about using Advanced Custom Fields plugin for WordPress or just using a custom field, for an image I have on my home page, which is currently hardcoded to a file URL within my media library.
I basically have a home-page-template.php file for my home page where I have created something of the following nature, within it:
So based on the above code within my home-page-template.php, can someone through the use of Advanced Custom Fields assist me on how to allow a user to change the home page some-image.jpg file to be whatever they like, without the need of physically going into the home-page-template.php file and manually changing this?
Basically require a means of replacing the
src=” http://mydomain.com/uploads/some-image.jpg” to
src=” http://mydomain.com/uploads/another-image.jpg”
basically, whatever the user would like to change it to.
Can someone please assist with the php code or perhaps point me to an article that would assist me in performing the above requirement.
Thanks.
Tony.
Why make the user change the URL to the image when you can just get them to upload a new image themselves?
Using ACF, you can simply add an image field to your home page and then use the following code in your template:
$home_image = get_field(‘your_field_name’);
if( $home_image ) {
echo wp_get_attachment_image( $home_image, $size = ‘full’ );
} else {
echo ““;
}
?>
I’m using `wp_get_attachment_image` here, but that depends on you selecting ‘Image ID’ as the ‘Return Value’ when you create your custom field.
Also, the ACF documentation is fantastic:
Hi,
Really appreciate the responses – will take a look and let you know how I go.
Thanks.
Tony.