The pings_open() WordPress PHP function determines whether the current post is open for pings.
Usage
pings_open( $post );
Example
if ( pings_open() ) {
echo "This post is open for pings.";
} else {
echo "This post is not open for pings.";
}
Parameters
$post(int|WP_Post, Optional) – Post ID or WP_Post object. Default current post. Default: null
More information
See WordPress Developer Resources: pings_open()
Examples
Display a message if the post is open for pings
if ( pings_open() ) {
echo '**This post is open for pings.**';
} else {
echo 'This post is not open for pings.';
}
Check if a specific post is open for pings
$post_id = 42;
if ( pings_open( $post_id ) ) {
echo "Post with ID $post_id is open for pings.";
} else {
echo "Post with ID $post_id is not open for pings.";
}
Display a list of posts open for pings
$posts = get_posts();
echo 'Posts open for pings:';
foreach ( $posts as $post ) {
if ( pings_open( $post->ID ) ) {
echo "- **{$post->post_title}**";
}
}
Add a CSS class to a post open for pings
$post_class = '';
if ( pings_open() ) {
$post_class .= ' open-for-pings';
}
echo "<div class=\"$post_class\">Post content here</div>";
Display a pingback count for posts open for pings
if ( pings_open() ) {
$ping_count = get_comments_number();
echo "This post has **$ping_count pingbacks**.";
} else {
echo 'This post is not open for pings.';
}