Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Change Home Page Image using Advanced Custom Fields

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #42829
    softprinciples
    Participant

    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.

    #125331
    TheDoc
    Member

    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.

    #125332
    TheDoc
    Member

    Also, the ACF documentation is fantastic:

    http://www.advancedcustomfields.com/docs/field-types/image/

    #125337
    softprinciples
    Participant

    Hi,

    Really appreciate the responses – will take a look and let you know how I go.

    Thanks.
    Tony.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘CSS’ is closed to new topics and replies.