WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to add a custom field value (if it exists) to the permalink?

share|improve this question
up vote 3 down vote accepted

Here's how I'd do it. I'm just going to say, I haven't tested this code at all, so I don't know if it even works. It's more of a starting point for you.

function jpb_custom_meta_permalink( $link, $post ){
  $post_meta = get_post_meta( $post->ID, '<insert your meta key here>', true );
  if( empty( $post_meta ) || !is_string( $post_meta ) )
    $post_meta = '<insert your default value (could be an empty string) here>';
  $link = str_replace( '!!custom_field_placeholder!!', $post_meta, $link );
  return $link;

add_filter( 'post_link', 'jpb_custom_meta_permalink', 10, 2 );

You would also have to go to your permalinks and change them to include '!!custom_field_placeholder!!', like so:


This will not add any significance to your permalinks, merely text. If you need to add meaning to the text that goes there, that's a lot more work.

share|improve this answer
We are looking for a solution like this to populate a custom field in the post editor with a source URL from Feed WordPress (Syndication) plugin. Basically, the Syndication plugin pulls the feed 'source', but sometimes, the feed owner doesn't include the 'source' url, so we want the editor to be able to add a 'source' URL if one does not exist, so that we can consistently display the target URL with the associated post. This code you have posted is for the "permalink," but do you think we can modify to pull the data from the plugin and add it to the custom field? – Tony Zeoli Jul 27 '11 at 15:18

Definitely no easy way since it's not part of Structure tags available for use in pretty permalinks setup.

For generic post it is probably easiest to edit slug manually.

Do you expect these posts to be generated by code or something?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.