YOURLS: WordPress to Twitter
How do I post excert using %F{} ? (3 posts)

  1. sandraqu
    Posted 3 years ago #

    I tried using %F{description}

    because my HTML's description is my excerpt, ie
    <meta name="description" content="here" />

    but nothing prints to twitter.


  2. sandraqu
    Posted 3 years ago #


    I'm trying to use YOURLS to Twitter (WordPress plugin) to output the excerpt.

    The plugin's instructions suggest

    %F{something}: custom post field 'something'. See get_post_meta().

    WordPress informs

    <?php $meta_values = get_post_meta($post_id, $key, $single); ?>

    Where $key is a string "(required) A string containing the name of the meta value you want."

    The HTML has

    <meta name="description" content="this is my excerpt" />

    Where the description meta has the excerpt's content.

    I tried using

    #in %F{description} %U

    and got "#in bit.ly/7493d0e". How can I get the excerpt to print? This is the php interpreting that %F

    if( preg_match_all( '/%F\{([^\}]+)\}/', $tweet, $matches ) ) {
        foreach( $matches[1] as $match ) {
            $field = get_post_meta( $id, $match, true );
            $tweet = str_replace('%F{'.$match.'}', $field, $tweet);
        unset( $matches );
  3. sandraqu
    Posted 3 years ago #

    For anyone wanting to do this, here is what I did to get it working. If you can improve this, feel free. I'm not a lithe PHP Developer.

    I added this conditional into core.php about line 454.

    if (strpos($tweet, '%E') !== false) {
                // Get post excerpt
                $post = get_post( $id );
                $post_exc = $post->post_excerpt;
                unset( $post );
                // Replace %E with post excerpt
                $tweet = str_replace('%E', $post_exc, $tweet);

    And, in WP, called %E in the Settings for YOURLS WordPress to Plugin Tweet message field: #in %E %U

    Obviously the "#in" is there so that the Tweet posts to LinkedIn.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • YOURLS: WordPress to Twitter
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic