Halloween Sale 15% off Ends in See the plans
PHP

Pull Quote Shortcode

Adds a [pull_quote] shortcode that sets a short quotation in large type, floated to the side on wide screens and full width on phones, to break up long articles.

Don’t have WPIDE yet? Install it on your site

Code

add_action( 'init', function () {
    wp_register_style( 'wpide-pullquote', false, array(), '1.0' );
    wp_add_inline_style( 'wpide-pullquote', '.wpide-pullquote{margin:1.5em 0;padding:.5em 0 .5em 1em;border-left:4px solid currentColor;font-size:1.35em;line-height:1.4;font-style:italic}.wpide-pullquote p{margin:0}.wpide-pullquote cite{display:block;margin-top:.5em;font-size:.7em;font-style:normal;opacity:.8}@media (min-width:700px){.wpide-pullquote.is-left{float:left;width:40%;margin:.3em 1.5em 1em 0}.wpide-pullquote.is-right{float:right;width:40%;margin:.3em 0 1em 1.5em}.wpide-pullquote.is-center{text-align:center;border-left:0;border-top:3px solid currentColor;border-bottom:3px solid currentColor;padding:.75em 0}}' );

    add_shortcode( 'pull_quote', function ( $atts, $content = '' ) {
        $atts  = shortcode_atts( array( 'align' => 'right', 'cite' => '' ), $atts, 'pull_quote' );
        $align = in_array( $atts['align'], array( 'left', 'right', 'center' ), true ) ? $atts['align'] : 'right';
        wp_enqueue_style( 'wpide-pullquote' );

        return sprintf(
            '<blockquote class="wpide-pullquote is-%s"><p>%s</p>%s</blockquote>',
            esc_attr( $align ),
            wp_kses( trim( $content ), array( 'em' => array(), 'strong' => array(), 'br' => array(), 'a' => array( 'href' => true ) ) ),
            '' !== $atts['cite'] ? '<cite>— ' . esc_html( $atts['cite'] ) . '</cite>' : ''
        );
    } );
} );

Notes

Example [pull_quote align="right" cite="Jane Doe"]Great design is invisible.[/pull_quote]; align can be left, right or center.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.