I usually write in javascript, but I'm currently trying to set up a Wordpress theme for a side project. I've found a few resources outlining how to use a set featured image as a div background image through inline styling, but they're a little old. I'm currently trying a basic method I found, and have tried updating it to match the current Wordpress Docs, but I'm new to PhP.
In my functions file I have:
add_theme_support( 'post-thumbnails' );
In my template file I have:
<?php $bgImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large'); ?>
<section style="background: url('<?php echo $bgImg[0]; ?>') no-repeat;">
</section>
The section is rendering but the dev tools show "background: url((unknown))"
- Could someone point a poor javascript-er in the right direction with the php here?
- If someone is more familiar with wordpress, can they confirm for me that 'large' is a default image size, or do I need to register it?