W
W
wordpress-good2020-06-16 18:50:39
WordPress
wordpress-good, 2020-06-16 18:50:39

How to trim url when saving posts?

I need it to be saved with a shortened url when saving a post, a maximum of 3 words, I added code (2 hooks) to functions.php, but they do not work, tell me what I'm doing wrong

function action_function_name( $post_ID) {

$post_url = get_permalink ( $post_ID );

return wp_trim_words( $post_url, 3, $more=null );
}
add_action( 'save_post', 'action_function_name', 10, 3 );

function trimwords()
{
global $post;

$post_url = get_permalink( $post);
return wp_trim_words( $post_url, 3, $more=null );


}
add_action('save_post_news', 'trimwords', 10);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-06-16
@wordpress-good

https://qna.habr.com/answer?answer_id=1657711#answ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question