How to add background image control to page admin controls?

I understand that each page is assigned its own class such as .page-id-22 & I can use that to assign a background image to it using the stylesheet but I’ve seen a theme that adds a control to the admin section of the page itself, which is what I’d like to accomplish.

Basically, the user would be able to click & upload an image to an individual page, as needed, without the need to edit the stylesheet.

Would it be similar to some ideas posited in this dated discussion?

This question is different from this discussion because it’s not just the header & this is something that needs to be part of the theme which doesn’t make use of a plugin.

3 Answers
3

It can be done with a custom field and the CSS should be changed to .php file:

$image = get_post_meta( $post->ID, "ImagePathFromCustomField", true );
if ( $image != '' ) { 
    ?>
    <style type="text/css">
        .bg-image { 
            background-image: url(<?php echo $image; ?>); 
            background-repeat: repeat; 
        }
    </style>
    <?php
}

Leave a Comment