Are you getting stuck on placing a banner on all pages of the website as well as customizing the size, title, image, ... on the banner? Don’t worry, this can be done easily by creating a settings page on the back end, and then add some custom fields. Each custom field is a parameter to customize the banner. After that, just use a shortcode to display the banner on the page you want.

To do so, we use two following plugins:

  • Meta Box: a framework that helps you create custom fields easily and quickly. It’s free and available on wordpress.org.
  • MB Settings Page: it’s a premium extension of Meta Box that helps you create settings pages with a lot of options right on the back end effortlessly. Note that it’s required to install Meta Box to use the MB Settings Page extension.

Let’s get started!

Step 1: Create a Settings Page to Install the Banner

You have to create a settings page for each banner. Then, when you want to edit any banner, you just need to go to the corresponding settings page.

To create a settings page, go to Meta Box > Settings Page > New Settings Page. This is the UI provided by MB Settings Page. Just fill in the option you want for your settings page.

This is the UI provided by MB Settings Page

This is the settings page that I’ve created:

Create a Settings Page on the WordPress website

This page is still empty. Therefore, you have to add custom fields to create some options for the banner’s content and parameter.

Step 2: Add Custom Fields for the Settings Page

We need to add the following fields to the above settings page for the banner:

Field Name Field Type Content
Show Checkbox Display / Don’t display the banner
Image Single image Choose an image for the banner
Title Text Choose a title for the banner
Description Textarea Add a description for the banner
Color Color Add colors for the banner
Color’s description Color Add colors for the description
Title’s Position Radio Choose a position for the title
Description’s Position Radio Choose a position for the description

To add these above fields, we can use one of these two methods:

Method 1: Create custom fields using the Online Generator tool

To get more details about how to use the Online Generator tool, refer to this documentation. Upon creating fields with Online Generator UI, you will have the following code. You need to add this code to the functions.php file:

// Register meta boxes and fields for settings page
add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
    $meta_boxes[] = array(
        'id'             => 'colors',
        'title'          => 'Colors',
        'settings_pages' => 'banner',
        'tab'            => 'design',
        'fields' => array(
            array(
                'name' => 'Show',
                'id'   => 'show_banner',
                'type' => 'checkbox',
                'std'  => 0,
            ),
            array(
                'name' => 'Image',
                'id'   => 'image',
                'type' => 'single_image',
            ),
            array(
                'name' => 'Title',
                'id'   => 'title',
                'type' => 'text',
            ),
            array(
                'name' => 'Description',
                'id'   => 'description',
                'type' => 'textarea',
            ),
            array(
                'name' => 'Color’s title',
                'id'   => 'color_title',
                'type' => 'color',
            ),
            array(
                'name' => 'Color’s description',
                'id'   => 'color_description',
                'type' => 'color',
            ),
            array(
                'name' => 'Title’s Position',
                'id'   => 'position_title',
                'type' => 'radio',
                'options' => array(
                    'left' => 'left',
                    'center' => 'center',
                    'right' => 'right',
                ),
                'inline' => true,
            ),
            array(
                'name' => 'Description’s Position',
                'id'   => 'position_description',
                'type' => 'radio',
                'options' => array(
                    'left' => 'left',
                    'center' => 'center',
                    'right' => 'right',
                ),
                'inline' => true,
            ),
        ),
    );
    
    return $meta_boxes;
} );

Method 2: Create Custom Fields Using Meta Box Builder

After creating fields, move to the Settings tab, choose Settings Pages on the Show for section, and choose Banner for the Settings Page section to display the created fields to the Banner settings page.

Read more: Create custom fields with Meta Box Builders.

Display the created custom fields to the Banner settings page

Now the custom fields are ready, so you can start customizing the banner and uploading the image for it.

Customize the Banner setting page on WordPress back end

Next, we need to create a shortcode to display images in the desired positions.

Step 3: Create a Shortcode for the Banner

Next, add the following code to the functions.php file to create the shortcode for displaying the banner on the front end:

function short_code_banner() {
    // Banner 
    $settings = get_option( 'banner' );
    $image_ids = $settings['image'];
    $image_attributes = wp_get_attachment_image_src( $image_ids, 'full');

    $title = rwmb_meta( 'title', ['object_type' => 'setting'], 'banner' );
    $description = rwmb_meta( 'description', ['object_type' => 'setting'], 'banner' );

    $position_title = rwmb_meta( 'position_title', ['object_type' => 'setting'], 'banner' );
    $position_description = rwmb_meta( 'position_description', ['object_type' => 'setting'], 'banner' );

    $color_title = rwmb_meta( 'color_title', ['object_type' => 'setting'], 'banner' );
    $color_description = rwmb_meta( 'color_description', ['object_type' => 'setting'], 'banner' );

    $width_content = rwmb_meta( 'width_content', ['object_type' => 'setting'], 'banner' );

    if ( !is_admin() ) {
        
        echo '<div class="banner" style="background-image: url(' .  $image_attributes[0]  . ' )">';
            echo '<div class= "content-banner" style="width: ' . $width_content . ' "> ';

                echo '<h2 style="color: ' . $color_title . ' " class="title-banner ' . $position_title . ' ">' . $title . '</h2>';
                
                echo '<div style="color: ' . $color_description . ' " class="description-banner ' . $position_description . ' ">' . $description . '</div>';
                
            echo '</div>';
        echo '</div>';
    }
}
add_shortcode( 'banner-shortcode', 'short_code_banner' );

This time, just paste the shortcode [banner-shortcode] anywhere you want to display the banner such as footer, header, posts, …

Step 4: Display the Banner on the Front End

For example, I want to add a product image to the sidebar so I head to Dashboard > Appearance > Widget and paste the shortcode:

Use shortcode to display the Banner on the Front End

However, the banner doesn’t look very well. Therefore, I’m going to style it a bit.

Style the banner created by Meta Box plugin

If you want your banner to be as beautiful as the below image, go to Customizer > Additional CSS to style the image.

Style the image of the banner created with Meta Box plugin

This is the CSS code that I’ve used to customize the image:

.banner {
        position: relative;
    height: 500px;
    background-repeat: no-repeat!important;
    background-size: cover;
        background-position: center;
}

.banner .left {
    text-align: left;
}

.banner .right {
    text-align: right;
}

.banner .center {
    text-align: center;
}

.content-banner {
    width: 50%;
    position: absolute;
    top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

Done! The banner has displayed on all pages that you placed the shortcode.

Last Words

Not every theme supports areas for advertising, introduction, ... on the website. Therefore, creating a custom field to display the banner is extremely useful. Especially, this method allows WordPress users to customize the size, font, color, background image, ... and place banners on all the pages on the website with just one click. If you have any questions about adding a custom field to display the banner, leave a comment!

Other case studies you might be interested in

  1. Create A Dynamic Landing Page in WordPress Using Custom Field
  2. Create a Filter to Find Hotels by Location
  3. Create an OTA Website Like Booking.com with Meta Box Plugin - P1: Create a Page to Introduce Hotel Rooms
  4. Create an OTA Website Like Booking.com with Meta Box Plugin - P2: Create Filters on the Archive Page
  5. Create an OTA Website Like Booking.com with Meta Box Plugin - P3: Create Filters for Single Hotel Pages
  6. Create Dynamic Favicon in WordPress using Meta Box plugin
  7. Create Posts Series in WordPress Using Meta Box
  8. Display The Latest Products Section - P2 - Using Meta Box and Elementor
  9. Display The Latest Products Section - P3 - Using Meta Box And Oxygen
  10. How to Add Custom Fields for WooCommerce - P2 - Using MB Views
  11. How to Add Custom Fields to Display Banners using Meta Box Plugin
  12. How to Add Guest Authors and Guest Posts - Using Meta Box
  13. How to Add Related Posts - Using Custom Fields
  14. How to Build a Hotel Booking Website Using Meta Box - P1
  15. How to Build a Hotel Booking Website Using Meta Box - P2 - Booking Page in Backend
  16. How to Build a Hotel Booking Website Using Meta Box - P4 - Booking Management Page
  17. How to Build a Hotel Booking Website Using Meta Box – P3 – Booking Page for Customer
  18. How to Create a Classified Ads Website using Meta Box
  19. How to Create a Custom 404 Page in WordPress - P1 - Using Meta Box and Elementor
  20. How to create a FAQs page - P5 - Using Meta Box and Breakdance
  21. How to Create a Product Page - P2 - Using Meta Box and Oxygen
  22. How to Create a Product Page - P3 - Using Meta Box and Bricks
  23. How to Create a Product Page - P4 - Using Meta Box and Elementor
  24. How to Create a Product Page - P5 - Using Meta Box and Gutenberg
  25. How to Create a Product Page - P6 -Using Meta Box and Breakdance
  26. How to Create a Product Page - P7 - Using Meta Box + Kadence
  27. How to Create a Product Page - P8 - Using Meta Box and Brizy
  28. How to Create a Product Page - P9 - Using Meta Box and Divi
  29. How to Create a Product Page using Meta Box Plugin
  30. How to Create a Reading Progress Bar in WordPress Posts - P1 - Using MB Views
  31. How to Create a Recipe - P2 - Using Meta Box and Oxygen
  32. How to Create a Recipe - P3 - Using Meta Box and Elementor
  33. How to Create a Recipe - P4 - Using Meta Box and Bricks
  34. How to Create a Recipe - P5 - Using Meta Box and Zion
  35. How to Create a Recipe - P6 - Using Meta Box and Brizy
  36. How to Create a Recipe - P7 - Using Meta Box and Breakdance
  37. How to Create a Recipe - P8 - Using Meta Box and Kadence
  38. How to Create a Recipe - P9 - Using Meta Box and Divi
  39. How to Create a Recipe with Meta Box Plugin
  40. How to Create a Simple Listing - P2 - Using Meta Box and Bricks
  41. How to Create a Simple Listing - P3 - Using Meta Box and Breakdance
  42. How to Create a Simple Listing - P4 - Using Meta Box and Elementor
  43. How to Create a Team Members Page - P1- Using Meta Box and Elementor
  44. How to Create a Team Members Page - P2 - Using Meta Box and Oxygen
  45. How to Create a Team Members Page - P3 - Using Meta Box and Bricks
  46. How to Create a Team Members Page - P4 - Just Meta Box
  47. How to Create a Team Members Page - P6 - using Meta Box and Breakdance
  48. How to Create a Team Members Page - P7 - Using Meta Box and Kadence
  49. How to Create a Video Gallery Page - P2 - Using Meta Box + Bricks
  50. How to Create a Video Gallery Page - P3 - Using Meta Box and Breakdance
  51. How to Create a Video Gallery Page - P4 - Using Meta Box + Elementor
  52. How to Create a Video Gallery Page - P5 - Using MB Views
  53. How to Create a Video Gallery Page - P6 - Using Meta Box and Zion
  54. How to Create a Video Gallery Page - P7 - Using Meta Box and Kadence
  55. How to Create a Video Gallery Page Using Meta Box + Oxygen
  56. How to Create ACF Flexible Content Field with Meta Box
  57. How to Create an Auto-Updated Cheat Sheet in WordPress
  58. How to Create an FAQs Page - P1 - Using Meta Box and Elementor
  59. How to create an FAQs page - P2 - Using Meta Box and Oxygen
  60. How to create an FAQs page - P4 - Using Meta Box and Bricks
  61. How to Create an FAQs Page - P6 - Using MB Views
  62. How to Create an FAQs Page - P7 - Using Meta Box and Divi
  63. How to Create an FAQs Page - P8 - Using Meta Box and Kadence
  64. How to Create an FAQs Page - P9 - Using MB Blocks
  65. How to Create an FAQs Page -P3- Using Meta Box
  66. How to Create Buttons with Dynamic Link using Custom Fields
  67. How to Create Category Thumbnails & Featured Images Using Custom Fields
  68. How to Create Download and Preview Buttons - P1 - Using Meta Box and Bricks
  69. How to Create Download and Preview Buttons - P2 - Using Meta Box and Oxygen
  70. How to Create Download and Preview Buttons - P3 - Using MB Views
  71. How to Create Download Buttons in WordPress - Using Custom Fields
  72. How to Create Dynamic Landing Page in WordPress - P1 - Using Meta Box and Elementor
  73. How to Create Dynamic Landing Page in WordPress - P2 - Using Meta Box and Bricks
  74. How to Create Menus for Restaurants - P1 - Using Meta Box and Elementor
  75. How to Create Menus for Restaurants - P2- Using Meta Box and Bricks
  76. How to Create Notification Using Custom HTML Field
  77. How to Create Online Admission Form for School or University
  78. How to Create Online Reservation Form for Restaurants using Meta Box
  79. How to Create Reading Time to Your WordPress Posts - Using MB Views
  80. How to Create Relationships - P1 - Using Meta Box and Oxygen
  81. How to Create Relationships - P2 - Using Meta Box and Bricks
  82. How to Create Relationships - P3 - Using MB Views
  83. How to Create Relationships - P4 - Using Meta Box and Breakdance
  84. How to Create Taxonomy Thumbnails & Featured Images - P2 - Using Meta Box and Oxygen
  85. How to Create Taxonomy Thumbnails & Featured Images - P3 - Using Meta Box and Bricks
  86. How to Create Taxonomy Thumbnails & Featured Images - P4 - Using MB Views
  87. How to Create YouTube Video Timestamps on WordPress Website - P1 - Using MB Views
  88. How to Display a Video Playlist - P1- Using MB Views
  89. How To Display All Listings On A Map With Meta Box
  90. How to Display Author Bio in WordPress - P1 - Using Meta Box and Bricks
  91. How to Display Author Bio in WordPress - P2 - Using MB Views
  92. How to Display Dynamic Banners in WordPress - P3 - Using MB Views
  93. How to Display Images from Cloneable Fields - P1 - with Gutenberg
  94. How to Display Images from Cloneable Fields - P2 - Using Meta Box and Oxygen
  95. How to Display Images from Cloneable Fields - P3 - with Elementor
  96. How to Display Images from Cloneable Fields - P4 - with Bricks
  97. How to Display Opening Hours for Restaurants - P1 - Using Meta Box + Gutenberg
  98. How to Display Opening Hours for Restaurants - P2 - Using Meta Box and Oxygen
  99. How to Display Product Variations - P1 - Using Meta Box and Gutenberg

Leave a Reply

Your email address will not be published. Required fields are marked *