WordPress.org

Ready to get started?Download WordPress

Forums

My plugin is choking on bloginfo(url) (4 posts)

  1. kygerbailey
    Member
    Posted 6 years ago #

    Ok. Today I'm writing my first plugin. It's pretty simple: after each post, display a link to a url with the name of the blog, url, and post_ID.

    But it keeps choking when it hits the part for

    <?php bloginfo('url'); ?>

    Here is the complete code:

    function retweet ($content) {
    	$content = $content . '<a>+<?php bloginfo('url'); ?>/?p=<?php the_ID(); ?>">Retweet</a>';
    	return $content;
    }
    
    add_filter('the_content', 'retweet');
  2. NC@WP
    Member
    Posted 6 years ago #

    You can't nest <?php ... ?> tags... Additionally, bloginfo() and the_ID() do not return values, they output them...

    Try this instead:

    function retweet($content) {
      ob_start();
      echo "\r\n";
      echo '<a href="';
      bloginfo('url');
      echo '/?p=';
      the_ID();
      echo '">Retweet</a>';
      echo "\r\n";
      return $content . ob_get_clean();
    }
  3. kygerbailey
    Member
    Posted 6 years ago #

    That seems to be linking directly to the same post url using the dynamic address. However, I'm trying to build a HREF url that includes text and the_title() and bloginfo(url) and the_ID().

    The link should go to:

    http://twitter.com/home/?status=Retweet: Blog Title Var http://someblog.com/?p=1

    The link text should be: Retweet

    Any mods you can help with to complete this?

  4. kygerbailey
    Member
    Posted 6 years ago #

    Much thanks to NC@WP for helping rewrite the function in my first plugin.

    You can now download it at:

    http://kygerbailey.com/wordpress-plugins/retweet

Topic Closed

This topic has been closed to new replies.

About this Topic