WordPress.org

Ready to get started?Download WordPress

Forums

Automatic Featured Image Posts
[resolved] Auto text (4 posts)

  1. Willem-Siebe
    Member
    Posted 1 year ago #

    Good afternoon,

    This plugin is REALLY usefull for portfolio website! I gave it 5 star rating.

    One question though. I wanted to use this in my functions.php to auto load some text in de post:

    // Default post editor text //
    
    function diww_default_post_content( $content ) {
    	$content = '<ul class="details">
    <li>Jaar:</li>
    <li>Afmeting b x h:</li>
    <li>Techniek: </li>
    <li>Prijs:</li>
    <li>Beschikbaar: Ja (<a href="mailto:info@daniqueidema.nl">stuur een e-mail</a>)</li>
    </ul>';
    	return $content;
    }
    
    add_filter( 'default_content', 'diww_default_post_content' );

    But this is not visible in the post your plugin makes. I tried this but it did not work:

    // post editor text //
    
    function afip_new_post_content ( $new_post_content ) {
    $new_post_content = '<p>test</p>';
    return $new_post_content;
    }
    
    add_filter( 'afip_new_post_content', '', $post_id );

    Can you help me?

    Kind regards Willem

    http://wordpress.org/extend/plugins/automatic-featured-image-posts/

  2. Jeremy Felt
    Member
    Plugin Author

    Posted 1 year ago #

    Both examples are close, but a little tweaking is needed.

    The filter you are trying to use is afip_new_post_content, so that will always be the first argument for add_filter(). The second argument should be the function you are using to handle the content, in this case diww_default_post_content(). The third argument is for priority, and the fourth for number of arguments to pass to the filter.

    In this case, you are replacing the content entirely rather than appending, so you can probably leave out the third and fourth arguments.

    Try this:

    // Default post editor text
    function diww_default_post_content() {
        $content = '<ul class="details">
            <li>Jaar:</li>
            <li>Afmeting b x h:</li>
            <li>Techniek: </li>
            <li>Prijs:</li>
            <li>Beschikbaar: Ja (<a href="mailto:info@daniqueidema.nl">stuur een e-mail</a>)</li>
        </ul>';
        return $content;
    }
    add_filter( 'afip_new_post_content', 'diww_default_post_content' );

    For more information on the arguments used with add_filter(), check out the Codex article.

  3. Willem-Siebe
    Member
    Posted 1 year ago #

    You're the man! Thanks for the effort!

  4. Jeremy Felt
    Member
    Plugin Author

    Posted 1 year ago #

    Marking this as resolved.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic