Mika MAtikainen
Apr 15, 2020 · 4 min read
How to Add “View HTML” Button in WordPress?
// Add "View HTML" button for each row on Edit Post screen
function wps_modify_list_row_actions($actions, $post) {
// check for CPT and capability if needed, use nonce if needed
$html = isset($actions['view']) ? $actions['view'] : null;
$html = $html ? str_replace('View', 'HTML', $html) : null;
$html = $html ? str_replace('href="', 'target="_blank" rel="noopener noreferrer" title="View HTML of frontend page" href="view-source:', $html) : null;
$actions = $html ? array_merge($actions, array('html' => $html)) : $actions;
return $actions;
}
add_filter('page_row_actions', 'wps_modify_list_row_actions', 10, 2);
add_filter('post_row_actions', 'wps_modify_list_row_actions', 10, 2);