0

I am looking to add a hero image to my site's home page (blog format) via the dashboard.

I have successfully used Advanced Custom Fields (ACF) to add hero images to static pages and posts. However I've been unable to figure out how to add a custom field to the home page when it is in 'recent posts' mode as the dashboard provides no control over the home page when it is in this mode (as far as I understand).

A solution using ACF would be appreciated but is non-essential.

1

There are a lot of variables to this question so bear with me as I give you a solution that will get you close.

assuming the field is called myimage and you're returning the image url in the field control...

open your home.php file in your child them (if you don't have a child theme, make one and copy the home.php from the main theme. Then in the home.php that is in your child theme put this code:

<?php if( get_field('myfield') ): ?>

    <img src="<?php the_field('myfield'); ?>" />

<?php endif; ?>

where ever you want it to appear on the homepage.

If you want the hero to be in the header you may need to use the header.php and use this code.

<?php 
if ( is_home() ) {
    // This is the blog posts index
    if( get_field('myfield') ): ?>
        <img src="<?php the_field('myfield'); ?>" />

    <?php endif;
} else {
    // This is not the blog posts index
}
?>
4
  • Thanks for the response! I understand that part of the solution. What I'm struggling with is how to get access to the field to input the image url via the WP Dashboard using a blog format home page. Usually say if I want to create field called 'myfield' on a static front page, I would set the custom location rule to 'Page Type -> is equal to -> Front Page'. Then when I edit the page I would see the 'myfield' input. However this is not the case when using a blog format home page as I can't seem to figure out how to get access to the 'myfield' input. – iNaesu May 24 '17 at 10:56
  • As far as I can see, the Dashboard does not provide means to edit the blog format home page. – iNaesu May 24 '17 at 11:03
  • Ahhh.. do you have pro? You need to create an options page. Youll add. Tiny piece of code to the functions.php. I can guide you through that if needed. – rudtek May 24 '17 at 12:59
  • I had a look at ACF Pro options. Looks like exactly what I need. The documentation looks clear & straightforward too. Now it's just to toss-up between whether to get Pro (just dipping my toes into WP dev for personal use at the moment) or use an uglier solution using ACF Free. I found out that the get_field() function also takes a $post_id variable so that could be a way around it. Thanks for pointing me in the right direction! – iNaesu May 24 '17 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.