RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment

Blockquotes with WordPress Shortcode

Blockquotes with WordPress Shortcode

Virtually all WordPress themes will style their blockquotes in a specific manner - not always to your liking. While it's super-simple to write some custom CSS and overwrite the default behaviour, our shortcode will permit you to preserve the theme-specific style and use another for basic text. The function supports nested shortcodes, meaning that you can use shortcodes inside the blockquote. The code isn't completely unlike our textbox shortcodes... apart from the fancy-pants formatting.

Again, using CSS is almost always a better means of formatting your page. There are times, however, where this might be useful.

The Result

In its most simplest form, a shortcode of [blockquote]Your content in here...[/blockquote] will generate the following. For the sake of the example we'll include a random quote (generated with shortcode of [qotz]).

"It is truer to say that martyrs create faith more than faith creates martyrs." — Miguel de Unamuno 

The Code

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

1
<?php 
2
/*
3
 Blockquotes with WordPress Shortcode
4
 http://www.beliefmedia.com/wordpress-blockquote-shortcode
5
*/
6
 
7
function beliefmedia_blockquote($atts, $content = null) {
8
 
9
  $atts = shortcode_atts(array(
10
    'width' => '490px',
11
    'maxwidth' => '90%',
12
    'padding' => '5px'
13
  ), $atts);
14
 
15
  /* Pixels or percentage */
16
  $type = (strpos($atts['width'], '%') !== false) ? '%' : 'px';
17
  $width = abs($atts['width']);
18
 
19
  /* Build container */
20
  $return .= '<div style="text-align: center; width: ' . $width . $type . '; max-width: ' . $atts['maxwidth'] . '; margin: 0px auto; padding: ' . $atts['padding']  . '">
21
<div style="text-align: left;">' . do_shortcode($content) . '</div>
22
</div>';
23
 
24
 return $return;
25
}
26
add_shortcode('blockquote', 'beliefmedia_blockquote');

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

Shortcode Attributes

Following attributes alter the blockquote presentation.

width

The width of the blockquote. Can be a percentage or pixel width. If none provided, defaults to pixels.

maxwidth

To preserve some semblance of a blockquote when used on some mobile devices, the blockquote will only scale to the maxwidth (90% seems to be okay)

padding

Applies a small padding to the blockquote. We apply 5 pixels by default.

Considerations

  • The blockquote supports nested shortcode and paragraphs.
  • See also: Text Boxes With WordPress Shortcode.

Download


Title: Blockquotes in WordPress (WP Plugin)
Description: Renders a blockquote in WordPress with shortcode.
  Download • Version 0.2, 1.4K, zip, Category: WordPress Plugins (General)
WordPress Shortcodes, (612.0B)    

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  AUS Eastern Standard Time (Virginia)

  Want to have a chat?
 

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment