I have a quick question.

Right now permalink url is automatically set by the title text you enter.

So when your title is i love marry, page url will be www.example.com/i-love-marry

I'm new to coding, but I presume that somewhere in the wordpress code there is a command similar to [permalink][title][/permalink]

Is it possible for permalink to be set by the content instead of the title?

Or is it possible to somehow modify a custom permalink that instead of /%postname%/ I would be able to set /%postcontent%/

I hope you get the idea.

I have searched everywhere and haven't found the answer.

Would appreciate your help.


  • 2
    Presumably you’re not going to have that much content? Or do you only want the first X words for the link? – Jacob Peattie Mar 16 '18 at 11:49
  • Yeah, content is short, up to 50 characters. – RaymondM Mar 16 '18 at 11:53

Try to put this in functions.php of your theme. It's untested in this form, but should work.

 * Change the Permalink on save / update
function wpse_297006_rewrite_slug( $post_id, $post, $update ){
  // check if it's a post
  if (!(get_post_type( $post_id ) === 'post')) return;
  // check if it's not a revision
  if (!(wp_is_post_revision( $post_id ) === false)) return;

  // check if it's not a revision
  $content = get_post_field('post_content', $post_id);
  // set the args
  $args = [
    'ID' => $post_id,
    'post_name' => strtolower( sanitize_title( $content ) ),

  // unhook this method to prevent infinite loop
  remove_action('wp_insert_post', 'wpse_297006_rewrite_slug');
  // apply $args when post is saved
  wp_update_post( $args );
  // re-hook this method
  add_action('wp_insert_post', 'wpse_297006_rewrite_slug', 10, 3);

add_action('wp_insert_post', 'wpse_297006_rewrite_slug', 10, 3);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.