add_shortcode example

/** * Constructor */
    public function __construct() {
        // Hack to get the [embed] shortcode to run before wpautop().         add_filter( 'the_content', array( $this, 'run_shortcode' ), 8 );
        add_filter( 'widget_text_content', array( $this, 'run_shortcode' ), 8 );
        add_filter( 'widget_block_content', array( $this, 'run_shortcode' ), 8 );

        // Shortcode placeholder for strip_shortcodes().         add_shortcode( 'embed', '__return_false' );

        // Attempts to embed all URLs in a post.         add_filter( 'the_content', array( $this, 'autoembed' ), 8 );
        add_filter( 'widget_text_content', array( $this, 'autoembed' ), 8 );
        add_filter( 'widget_block_content', array( $this, 'autoembed' ), 8 );

        // After a post is saved, cache oEmbed items via Ajax.         add_action( 'edit_form_advanced', array( $this, 'maybe_run_ajax_cache' ) );
        add_action( 'edit_page_form', array( $this, 'maybe_run_ajax_cache' ) );
    }

    

function _wp_post_thumbnail_context_filter_remove() {
    remove_filter( 'wp_get_attachment_image_context', '_wp_post_thumbnail_context_filter' );
}

add_shortcode( 'wp_caption', 'img_caption_shortcode' );
add_shortcode( 'caption', 'img_caption_shortcode' );

/** * Builds the Caption shortcode output. * * Allows a plugin to replace the content that would otherwise be returned. The * filter is {@see 'img_caption_shortcode'} and passes an empty string, the attr * parameter and the content parameter values. * * The supported attributes for the shortcode are 'id', 'caption_id', 'align', * 'width', 'caption', and 'class'. * * @since 2.6.0 * @since 3.9.0 The `class` attribute was added. * @since 5.1.0 The `caption_id` attribute was added. * @since 5.9.0 The `$content` parameter default value changed from `null` to `''`. * * @param array $attr { * Attributes of the caption shortcode. * * @type string $id ID of the image and caption container element, i.e. `<figure>` or `<div>`. * @type string $caption_id ID of the caption element, i.e. `<figcaption>` or `<p>`. * @type string $align Class name that aligns the caption. Default 'alignnone'. Accepts 'alignleft', * 'aligncenter', alignright', 'alignnone'. * @type int $width The width of the caption, in pixels. * @type string $caption The caption text. * @type string $class Additional class name(s) added to the caption container. * } * @param string $content Optional. Shortcode content. Default empty string. * @return string HTML content to display the caption. */
Home | Imprint | This part of the site doesn't use cookies.