I have various pages with sliders and I need to give the client the ability to change those images in the sliders in a easy way.

I thought on setting the slider image background based on each page featured image to make it easy to give a front-end solution for the client to have this control since I didn't make the theme.

Has anyone ever had this problem? Any solutions or ideas are welcome :)

1 Answer 1


For those who wondered the same thing as me, here is a solution:

I've got various references along the way to solve this so sorry for the lack of some links. Most of the solution don't come from me, I merely picked some pieces and put it together.

I used Revolution Slider and OptionTree to create the slider and the front-end options for the client to use.

You'll need two pieces of code on your "functions.php":

//Function to get id based on slug/link
function get_attachment_id_from_src ($image_src) {
    global $wpdb;
    $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
    $id = $wpdb->get_var($query);
    return $id;

// Define Featured Image based on OptionTree Theme Options
function defineFeaturedImage () {

    if (is_page()) {
        $page_id = get_the_ID();

        $post_slug = get_post_field( 'post_name', get_post() );

        if (is_page('/')) {
            $optiontree_id = 'bg_home';

        } elseif (is_page('firstpage')) {
            $optiontree_id = 'bg_firstpage';


    $url_featured = ot_get_option( $optiontree_id );

    $featured_id = get_attachment_id_from_src( $url_featured );

    if (!empty($page_id) && !empty($featured_id)) {

        set_post_thumbnail( $page_id, $featured_id );

add_action( 'pre_get_posts', 'defineFeaturedImage', 10, 3);

After that you just need to configure OptionTree for the options like the ones above with the ID just like each page you need to change (you need to add more elseif to change more pages, this code you still need to add one at a time). On Revolution Slider you need to configure the slider as any of the "Post Based" sliders type.

With that, revolution slider will change its background (if you set it to based on the post/page featured image), and even add any data from wordpress in the slider based on post/page.

So you just use this code above and OptionTree to control the featured image on each post/page.

Hope it helps someone :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.