• I’m developing my own theme and I need to run an if conditional based on whether the background image is in use or if it’s just a regular background color. How would I go about this?

    Basically in short, when the background image is in use it will be an ad, so I want my header pushed down to show what would effectively be a banner ad built into the background image. When no background image is defined, I want my header to be in its normal state. Basically the way cnn.com and imdb.com do their backgrounds (when they have them).

    • This topic was modified 7 years, 3 months ago by AJinNYC2112.
    • This topic was modified 7 years, 3 months ago by AJinNYC2112.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Bunty

    (@bhargavbhandari90)

    Are you using media library’s image for background?

    Thread Starter AJinNYC2112

    (@ajinnyc2112)

    Yes, the background images will be pulled from the media library.

    Bunty

    (@bhargavbhandari90)

    Ok. I you need to save that image url into options table.
    After that you can get the attachment id of that image from the url by doing some custom code like this:

    global $wpdb;
     $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url )); 

    So you can get the image id from this and thus you can check wich image is set as a background.

    • This reply was modified 7 years, 3 months ago by Bunty.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Detect if a Background Image is in use’ is closed to new replies.