简体   繁体   中英

How to get background Image using variable path in inline html?

I have my own wordpress template with option setting. My option setting having option for background Image path. I saved this option value in variable .Now how i can add this option setting value to get background Image for specific div class?

You'll need a page that you can put both CSS and PHP on, like header.php in your template. Be sure to note that this CSS hack is there so that you can re-add it when you update the theme.

Now, in your header.php file, just before the </head> tag, add this:

<style type='text/css'>
    /* div selector */ {
        background: url(<?php echo get_option("option_name"); ?>);
    }
</style>
</head>

You'll need to add a CSS selector to select the div you want to have tha background image, and you'll need to make sure that the background image links correctly. You may need to add /wp-content/ or similar things to the CSS or the option value if the image doesn't link correctly at first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM