- You already have
<option value="">...</option>
you just need some extra attrs for it - You need to load current value and if value equals
$page->ID
than add attrselected="selected"
Here’s how it could be done:
<select name="easyreg_redirect_page">
<option selected="selected" disabled="disabled" value=""><?php echo esc_attr( __( 'Select page' ) ); ?></option>
<?php
$selected_page = get_option( 'option_key' );
$pages = get_pages();
foreach ( $pages as $page ) {
$option = '<option value="' . $page->ID . '" ';
$option .= ( $page->ID == $selected_page ) ? 'selected="selected"' : '';
$option .= '>';
$option .= $page->post_title;
$option .= '</option>';
echo $option;
}
?>
</select>
where’s option_key
you should enter options key where your value can be found ( where it saves it )
also, you could use wordpress selected
function to write selected="selected"
, then it would be like these:
$option = '<option value="' . $page-ID . '" ' . selected( $selected_page, $page->ID ) . '>';