Question

I want to add the Page URL as a custom column to the Pages admin table. Here is where I am at with the code. Code is in the theme's functions.php.

function lrh_modify_page_table( $column ) {
    $column['lrh_url'] = 'URL';

    return $column;
}
add_filter( 'manage_pages_columns', 'lrh_modify_page_table' );

function lrh_modify_page_table_row( $column_name, $post_id ) {

    $url = get_permalink( $post_id, true);

    switch ($column_name) {
        case 'lrh_url' :
            echo $url;
            break;

        default:
    }
}

add_action( 'manage_pages_custom_column', 'lrh_modify_page_table_row', 10, 2 );

Right now it is returning the url as http://example.com/%pagename%/. How do I get it to return the actual URL of the page?

Was it helpful?

Solution

Remove the true parameter in the get_permalink function

$url = get_permalink( $post_id );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top