Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggregation Enquires Welcome

Example Interest Rates: Home Loan Variable: 2.54% (2.74%*) • Home Loan Fixed: 3.74% (3.8%*) • Fixed: 2.48% (2.94%*) • Variable: 2.54% (2.74%*) • Investment IO: 2.3% (3.76%*) • Investment PI: 2.04% (3.8%*)

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 (Washington)

  Want to have a chat?
 

RELATED READING

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment