WP HOOKS
filtrod 1.5.0

post_link

Args 3Plik wp-includes/link-template.phpDokumentacja WP ↗

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;
}

Only applies to posts with post_type of 'post'.

Parametry

ParametrTypOpis
$permalinkstringThe post's permalink.
$post\WP_PostThe post in question.
$leavenameboolWhether 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
}

Popularne w tej kategorii