Home / Admin / Detect Orphaned Content in WordPress Admin
Duplicate Snippet

Embed Snippet on Your Site

Detect Orphaned Content in WordPress Admin

Identify published posts and pages that are not linked internally from other published content on your website. This helps improve SEO, content discoverability, and site structure.

Installation:
Add this snippet as a PHP Snippet in WPCode and set it to Auto Insert → Run Everywhere. After activation, an "Orphaned Content" column will appear in Posts and Pages. Content marked "Potentially Orphaned" may need internal links from other pages or posts.

Code Preview
php
<?php
<?php
/**
 * Snippet: Detect Orphaned Content in WordPress Admin
 * Description: Adds an admin column that identifies content which may not be internally linked from other published posts or pages.
 *
 * Curated by: Avijit Datta
 * Agency: CypraWeb Digital
 * Website: https://cyprawebdigital.com
 *
 * Version: 1.0
 */
add_filter('manage_posts_columns', 'cwd_add_orphaned_content_column');
add_filter('manage_pages_columns', 'cwd_add_orphaned_content_column');
function cwd_add_orphaned_content_column($columns) {
    $columns['cwd_orphaned'] = 'Orphaned Content';
    return $columns;
}
add_action('manage_posts_custom_column', 'cwd_show_orphaned_content_status', 10, 2);
add_action('manage_pages_custom_column', 'cwd_show_orphaned_content_status', 10, 2);
function cwd_show_orphaned_content_status($column, $post_id) {
    if ($column !== 'cwd_orphaned') {
        return;
    }
    $current_url = get_permalink($post_id);
    if (!$current_url) {
        echo '—';
        return;
    }
    global $wpdb;
    $like_url = '%' . $wpdb->esc_like($current_url) . '%';
    $count = $wpdb->get_var(
        $wpdb->prepare(
            "
            SELECT COUNT(ID)
            FROM {$wpdb->posts}
            WHERE post_status = 'publish'
            AND post_type IN ('post','page')
            AND ID != %d
            AND post_content LIKE %s
            ",
            $post_id,
            $like_url
        )
    );
    if ($count > 0) {
        echo '<span style="color:green;font-weight:bold;">Linked</span>';
    } else {
        echo '<span style="color:#d63638;font-weight:bold;">Potentially Orphaned</span>';
    }
}

Comments

Add a Comment