filtrod 1.5.0
post_link
Opis
Zmienia permalink wpisu — np. własna struktura linków dla niestandardowego typu treści.
Przykład użycia
add_filter( 'post_link', ... )php
add_filter( 'post_link', 'wpdocs_book_permalink', 10, 3 );
function wpdocs_book_permalink( $permalink, $post, $leavename ) {
if ( 'book' === $post->post_type ) {
return home_url( '/ksiazki/' . $post->post_name . '/' );
}
return $permalink;
}
add_filter( 'post_link', 'wpdocs_book_permalink', 10, 3 );
function wpdocs_book_permalink( $permalink, $post, $leavename ) {
if ( 'book' === $post->post_type ) {
return home_url( '/ksiazki/' . $post->post_name . '/' );
}
return $permalink;
}Only applies to posts with post_type of 'post'.
Parametry
| Parametr | Typ | Opis |
|---|---|---|
$permalink | string | The post's permalink. |
$post | \WP_Post | The post in question. |
$leavename | bool | Whether to keep the post name. |
Wywołanie
Rejestracja callbackaphp
// rejestracja funkcji zwrotnej — podaj liczbę argumentów!
add_filter( 'post_link', 'twoja_funkcja', 10, 3 );
function twoja_funkcja($param_1, $param_2, $param_3) {
// Twój kod
}
// rejestracja funkcji zwrotnej — podaj liczbę argumentów!
add_filter( 'post_link', 'twoja_funkcja', 10, 3 );
function twoja_funkcja($param_1, $param_2, $param_3) {
// Twój kod
}Popularne w tej kategorii