Skip to content
Armando Lüscher edited this page Nov 17, 2017 · 18 revisions

WP to diaspora* provides some filters to change it's default style.

Title filter

This filter allows the title added at the beginning of your diaspora* post to be modified.

example to give the link a custom title

add_filter( 'wp2d_title_filter',
    function ( $default, $wp2d_post ) {
        return sprintf(
            '<p><strong><a href="%s" title="%s">%s</a></strong></p>',
            get_the_permalink( $wp2d_post->ID ),
            "Click here to read '{$wp2d_post->post->post_title}'",
            $wp2d_post->post->post_title
        );
    }, 10, 2 );

Post filter

This filter allows the post content to be modified.

example to show the word count below the post

add_filter( 'wp2d_post_filter',
    function ( $default, $wp2d_post ) {
        $word_count = str_word_count( $default );

        return "{$default}<br><p>Word count: {$word_count}</p>";
    }, 10, 2 );

Excerpt filter

This filter allows the post excerpt to be modified.

example to show the character count below the post

add_filter( 'wp2d_excerpt_filter',
    function ( $default, $wp2d_post ) {
        $character_count = strlen( $default );

        return "{$default}<br><p>Character count: {$character_count}</p>";
    }, 10, 2 );

Tags filter

This filter allows the tags added at the bottom to be modified.

example to separate tags with a dot

add_filter( 'wp2d_tags_filter',
    function ( $default, $tags, $wp2d_post ) {
        $tags_string = implode( '', $tags );

        return "<p>{$tags_string}</p>";
    }, 10, 3 );

"Originally posted at" link filter

This filter allows the link to the original post added at the bottom to be modified.

example to make it a "Read More" link

add_filter( 'wp2d_posted_at_link_filter',
    function ( $default, $wp2d_post, $text ) {
        return sprintf(
            '<a href="%s">Read More</a>',
            get_the_permalink( $wp2d_post->ID )
        );
    }, 10, 3 );

Captions filter

This filter allows the style of captions in your post to be modified.

example to add an arrow character as a prefix

add_filter( 'wp2d_image_caption',
    function( $default, $caption ) {
        return "{$caption}";
    }, 10, 2 );

Shortcodes filter

This filter controls which shortcodes are allowed in your diaspora* posts.

example to allow the shortcode foobar

add_filter( 'wp2d_shortcodes_filter',
    function( $shortcodes ) {
        array_push( $shortcodes, 'foobar' );

        return $shortcodes;
    }, 10, 1 );

Content filters filter

This filter manages the filters added to the_content.

example to apply the foobar filter to the post content

add_filter( 'wp2d_content_filters_filter',
    function( $filters ) {
        array_push( $filters, 'foobar' );

        return $filters;
    }, 10, 1 );