I operate a couple of side blogs which i kind of aggregate into my primary blog. I personally use simplepie to parse the feeds from the other blogs, therefore the posts are now being produced instantly.

My typical publish is defined such as this:

  1. IMAGE

What I am searching to complete is instantly grab the web link, and place it right into a Custom Area. The custom area already is available within the publish, but I have to place the web link included in the publish content because the value.

I'd need only the link, with no html, therefore the value could be only a straight link - http://domain.com/fsdds

I understand you will find numerous plug ins that make this happen with images, however i haven't seen something that is going to do it with other things, like hyperlinks.

I published this at the Wordpress forums and was told I'd need to parse the whole publish content searching for the hyperlinks, that we understood, the issue is I am much less sure how to achieve that.


This is actually the function that grabs the very first image inside a publish:

function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches [1] [0];

      if(empty($first_img)){ //Defines a default image
        $first_img = "/images/default.jpg";
      return $first_img;

you'd simply need to replace the very first preg_match_all parameter to:


Add the entire function for your functions.php, and call that function out of your script. It will return the very first link it finds within the publish content.

Building on Anthony's answer, make use of the UPDATE Publish META after you have your link...

Put this inside your functions.php file:

function catch_that_link() {
      global $post, $posts;
      $first_link = '';
      $output = preg_match_all('/(https?://)?(www.)?([a-zA-Z0-9_%]*)\b.[a-z]{2,4}(.[a-z]{2})?((/[a-zA-Z0-9_%])+)?(.[a-z])?/', $post->post_content, $matches);
      $first_link = $matches [1] [0];

      if(empty($first_link)){ //Defines a default image
        return 'no link found';
      return $first_link;

Then inside your query loop, category file or whatever php file you'd perform the following


$post_id = 13; //replace the number with the specific post
$meta_key = 'key_example' //replace with your custom field name
$meta_value = catch_that_link();

update_post_meta($post_id, $meta_key, $meta_value); 

I have been considering this myself and also the solution needs to be to operate a function around the save_post action hook. Regrettably this really is undocumented within the Wordpress Codex and that i haven't had time for you to look further afield yet.

Just happened this Function Reference/add post meta

Still need a method to grab the web link in the publish and and place it as being the $metavalue though.