Forums

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

Home Forums Back End WordPress: Integrating custom fields/echos into Dynamic PHP/CSS stylesheets

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #148583
    jonathanengstrom
    Participant

    Hi All,

    I’d be really grateful of anyone who can help me out here! I am building a new wordpress theme where the user needs to be able to select a feature image (either though the built in function or by a custom field if needed), which then becomes the background image for a div.

    So far I have got it working using the following inside the head of the page:

    <style>
    
        <?php $functionName = get_post_meta($post->ID, 'CUSTOM-FIELD-NAME', true); if ($functionName) { ?>
    
                div{ 
                    background: url(<?php the_field('CUSTOM-FIELD-NAME'); ?>) 50% 50% no-repeat;
                    background-size:cover;
                }
    
        <?php } else { ?>
    
                div{ 
                    background: url(/path/to/fallbackImg.jpg) 50% 50% no-repeat;
                    background-size:cover;
                }
    
        <?php } ?>
    
    </style>
    

    What would be great if this could be combined with a dynamic stylesheet, like Chris talks about in this post here, so that the style end up all in the correct style sheets and nothing is being pulled though the head.

    Anybody got any ideas? Any help much appreciated!

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.