How to Center, Style, and Add Icons to Your Shortcodes Ultimate Box Titles
Content
Many users of the 'WP Shortcodes Plugin — Shortcodes Ultimate' want more control over their box titles, specifically how to center them, add icons, or style them with custom CSS. This is a common request, as the default plugin options don't include these specific features out-of-the-box. Based on community discussions, here are the most effective and safe methods to achieve these customizations.
Common Problems and Their Solutions
1. Centering the Box Title
The plugin does not have a built-in parameter to center the title text. However, you can easily achieve this with a small amount of custom CSS.
Solution:
- First, add a custom class to your
su_boxshortcode to target it specifically. For example:
[su_box title="Your Title" class="center-my-title"]Your content here...[/su_box] - Navigate to your WordPress Dashboard, then go to Shortcodes → Settings.
- Locate the Custom CSS code field and add the following CSS rule:
.su-box.center-my-title .su-box-title { text-align: center; } - Save the changes. This CSS will target the title inside your specific box and center the text.
2. Adding an Icon Before the Title
There is no direct shortcode parameter to insert an icon into the title. The method involves modifying the final HTML output with a filter, which is more advanced but effective.
Solution (Advanced):
Warning: Adding code to your theme's functions.php file is a powerful method. Always use a child theme and create a backup before proceeding.
- You can use a WordPress filter to modify the rendered HTML of the shortcode. The following code snippet is an example that adds an image icon before the title for all boxes with a specific custom class (
icon-title). - Add this code to your child theme's
functions.phpfile:
add_filter( 'do_shortcode_tag', 'su_custom_box_icon', 10, 4 );
function su_custom_box_icon( $output, $tag, $attr, $m ) {
if ( 'su_box' === $tag && isset( $attr['class'] ) && strpos( $attr['class'], 'icon-title' ) !== false ) {
// Replace the image URL with the path to your icon
$icon_html = '<img class="su-box-icon" src="https://yoursite.com/path/to/icon.png" alt="" style="vertical-align: middle; margin-right: 10px;" />';
$output = str_replace( '<div class="su-box-title"', $icon_html . '<div class="su-box-title"', $output );
}
return $output;
} - Use the shortcode with your new class:
[su_box title="Your Title" class="icon-title"]Your content here...[/su_box]
3. General Custom Styling (Colors, Borders, Width)
For almost any visual customization—like changing the inner background color, adding a border, or adjusting the width—the most future-proof method is to use the built-in Custom CSS editor.
Solution:
- Add a custom class to your shortcode, e.g.,
my-dark-box. - Go to Shortcodes → Settings and use the Custom CSS field to target that class. For example, to style the inner content area for a dark theme:
.su-box.my-dark-box .su-box-inner {
background-color: #333 !important;
color: #fff !important;
}
.su-box.my-dark-box {
border: 2px solid #555 !important;
max-width: 500px !important;
}
Important Considerations
- Avoid Editing Plugin Files: Some older threads suggest directly modifying the
shortcodes.phpfile. This is strongly discouraged. Any changes will be completely erased the next time the plugin updates, potentially breaking your site. - Use a Child Theme: When adding custom PHP code (like the icon filter), always place it in your child theme's
functions.phpfile to prevent your changes from being lost during a theme update. - CSS Specificity: You may need to use the
!importantrule in your CSS to override the plugin's default styles, which are often highly specific.
By leveraging custom CSS classes and the plugin's settings page, you can safely and effectively customize your boxes without touching core plugin files. For more complex changes, carefully implemented PHP filters offer a powerful solution.
Related Support Threads Support
-
How to add icon before title in a boxhttps://wordpress.org/support/topic/how-to-add-icon-before-title-in-a-box/
-
Align Title in Boxeshttps://wordpress.org/support/topic/align-title-in-boxes/
-
How can i have the title in the center in a Boxhttps://wordpress.org/support/topic/how-i-can-have-the-title-in-the-center-in-a-box/
-
How To Edit Sidebar Author Block and Author Blockhttps://wordpress.org/support/topic/how-to-edit-sidebar-author-block-and-author-block/
-
Custom style for boxhttps://wordpress.org/support/topic/custom-style-for-box/
-
Center the icon vertically in the boxhttps://wordpress.org/support/topic/center-the-icon-vertically-in-the-box/
-
changing box default sizehttps://wordpress.org/support/topic/changing-box-default-size/
-
Change box second background colorhttps://wordpress.org/support/topic/change-box-second-background-color/
-
Border color of the Boxhttps://wordpress.org/support/topic/border-color-of-the-box/
-
su_lightbox , how to change color of the close-lightbox X in top right corner?https://wordpress.org/support/topic/su_lightbox-how-to-change-color-of-the-close-lightbox-x-in-top-right-corner/
-
How to insert icon just before the title?https://wordpress.org/support/topic/how-to-insert-icon-just-before-the-title/
-
Box without Box Titlehttps://wordpress.org/support/topic/box-without-box-title/
-
su_box titlehttps://wordpress.org/support/topic/su_box-title/
-
Box title headinghttps://wordpress.org/support/topic/box-title-heading/