Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Randome background for elementor

I use Elementor pro in my site. I have big Background image in top of my homepage that I have many elements in that section. I want to have one random image from a group of images (can be in gallery or in folder). but i didn't fine any solution.

I tried any addon for elementor. elementor pro background slidet, the plus row background, and etc. but they only make a slides with default order and don't have random order. I also tried some slider plugin or elementor's slider addons (smart slider,...). but the elements that should be on the image (other than text and buttons) could not be added to them.

I tried some javascripts to do it (for example: https://element.how/elementor-slider-random/#comment-12854 and this: Random background image on refresh). but it didn't work.

I like to know there is any solution to use custom php code to elementor dynamic simple background image that apply all background setting?

is there any solution?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

protected function render() {
    $settings = $this->get_settings_for_display();

    $images = array_values( $settings['carousel'] ?? [] );
    if ( ! $images ) {
        return;
    }
    $count = count( $images );
    $image = random_int( 0, ( $count - 1 ) );
    $image = $images[ $image ] ?? null;
    if ( ! $image ) {
        return;
    }

    $image_url = Group_Control_Image_Size::get_attachment_image_src( $image['id'], 'full', [ 'full_size' => 'full' ] );

    echo '<img class="' . $this->get_name() . '-image" src="' . esc_attr( $image_url ) . '" alt="' . esc_attr( Control_Media::get_image_alt( $image ) ) . '" />';
}

Elementor create a custom widget and follow the code. I hope your problem will be solved.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!