Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

remove reading static page setting WordPress

I need to add code to some of my themes functions.php to disable the wordpress settings>reading..Front page displays choice

Thanks


Hi guys thanks for the try but none of these answers work.. I will try a different way to complete this task.

LOL when you increase your prize money the site charges you a second 90 cents..o well

Thanks and have a great day

Answers (3)

2011-11-18

Gabriel Reguly answers:

Hi RNWest,

--Edit: Sorry, remove_option_whitelist( 'reading' ) seems to be the correct code.

remove_option_whitelist( 'reading' )

--

Try with <em> unregister_setting( $option_group, $option_name, $sanitize_callback );</em>

<?php unregister_setting( 'reading', $option_name, $sanitize_callback ); ?>


Regards,
Gabriel


RNWest comments:

Hi
Sorry this did not work..

The wordpress feature I am trying to remove is in wp-admin/options-reading.php

If this helps


Gabriel Reguly comments:

Hi RNWest,

That file is hard-coded and you will need to edit it to remove the code, but when updating WordPress your changes will be lost.

However, with the following code in your functions.php you can prevent those fields from being changed:


if ( is_admin() ) {
function gr_filter_options( $whitelist_options ) {
$remove = array( 'reading' => array( 'show_on_front', 'page_on_front', 'page_for_posts' ) );
foreach( $remove as $page => $keys ) {
foreach ( $keys as $key ) {
if ( isset($whitelist_options[ $page ]) && is_array($whitelist_options[ $page ]) ) {
$pos = array_search( $key, $whitelist_options[ $page ] );
if ( $pos !== false )
unset( $whitelist_options[ $page ][ $pos ] );
}
}
}
return $whitelist_options;
}
add_filter( 'whitelist_options', 'gr_filter_options', 10, 1 );
}



Luis solution removes the link from the menu, but an user can still access the page wp-admin/options-reading.php.

Hope this helps you.

And I won't mind if you could afford adding more money to the prize ;-)

Regards,
Gabriel


Gabriel Reguly comments:

BTW, options-reading.php should be like this: (based on WordPress 3.3)


<?php
/**
* Reading settings administration panel.
*
* @package WordPress
* @subpackage Administration
*/

/** WordPress Administration Bootstrap */
require_once( './admin.php' );

if ( ! current_user_can( 'manage_options' ) )
wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );

$title = __( 'Reading Settings' );
$parent_file = 'options-general.php';

/**
* Display JavaScript on the page.
*
* @package WordPress
* @subpackage Reading_Settings_Screen
*/
function add_js() {
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function($){
var section = $('#front-static-pages'),
staticPage = section.find('input:radio[value="page"]'),
selects = section.find('select'),
check_disabled = function(){
selects.prop( 'disabled', ! staticPage.prop('checked') );
};
check_disabled();
section.find('input:radio').change(check_disabled);
});
//]]>
</script>
<?php
}
add_action('admin_head', 'add_js');

add_contextual_help($current_screen,
'<p>' . __('This screen contains the settings that affect the display of your content.') . '</p>' .
'<p>' . sprintf(__('You can choose what&#8217;s displayed on the front page of your site. It can be posts in reverse chronological order (classic blog), or a fixed/static page. To set a static home page, you first need to create two <a href="%s">Pages</a>. One will become the front page, and the other will be where your posts are displayed.'), 'post-new.php?post_type=page') . '</p>' .
'<p>' . __('You can also control the display of your content in RSS feeds, including the maximum numbers of posts to display, whether to show full text or a summary, and the character set encoding.') . '</p>' .
'<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>' .
'<p><strong>' . __('For more information:') . '</strong></p>' .
'<p>' . __('<a href="http://codex.wordpress.org/Settings_Reading_Screen" target="_blank">Documentation on Reading Settings</a>') . '</p>' .
'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
);

include( './admin-header.php' );
?>

<div class="wrap">
<?php screen_icon(); ?>
<h2><?php echo esc_html( $title ); ?></h2>

<form name="form1" method="post" action="options.php">
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th>
<td>
<input name="posts_per_page" type="text" id="posts_per_page" value="<?php form_option( 'posts_per_page' ); ?>" class="small-text" /> <?php _e( 'posts' ); ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="posts_per_rss"><?php _e( 'Syndication feeds show the most recent' ); ?></label></th>
<td><input name="posts_per_rss" type="text" id="posts_per_rss" value="<?php form_option( 'posts_per_rss' ); ?>" class="small-text" /> <?php _e( 'items' ); ?></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'For each article in a feed, show' ); ?> </th>
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'For each article in a feed, show' ); ?> </span></legend>
<p><label><input name="rss_use_excerpt" type="radio" value="0" <?php checked( 0, get_option( 'rss_use_excerpt' ) ); ?> /> <?php _e( 'Full text' ); ?></label><br />
<label><input name="rss_use_excerpt" type="radio" value="1" <?php checked( 1, get_option( 'rss_use_excerpt' ) ); ?> /> <?php _e( 'Summary' ); ?></label></p>
</fieldset></td>
</tr>

<tr valign="top">
<th scope="row"><label for="blog_charset"><?php _e( 'Encoding for pages and feeds' ); ?></label></th>
<td><input name="blog_charset" type="text" id="blog_charset" value="<?php form_option( 'blog_charset' ); ?>" class="regular-text" />
<span class="description"><?php _e( 'The <a href="http://codex.wordpress.org/Glossary#Character_set">character encoding</a> of your site (UTF-8 is recommended, if you are adventurous there are some <a href="http://en.wikipedia.org/wiki/Character_set">other encodings</a>)' ); ?></span></td>
</tr>
<?php do_settings_fields( 'reading', 'default' ); ?>
</table>

<?php do_settings_sections( 'reading' ); ?>

<?php submit_button(); ?>
</form>
</div>
<?php include( './admin-footer.php' ); ?>


Gabriel Reguly comments:

Err, sorry.
Actually there is something missing.
Correct options-reading.php follows:

<?php
/**
* Reading settings administration panel.
*
* @package WordPress
* @subpackage Administration
*/

/** WordPress Administration Bootstrap */
require_once( './admin.php' );

if ( ! current_user_can( 'manage_options' ) )
wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );

$title = __( 'Reading Settings' );
$parent_file = 'options-general.php';

/**
* Display JavaScript on the page.
*
* @package WordPress
* @subpackage Reading_Settings_Screen
*/
function add_js() {
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function($){
var section = $('#front-static-pages'),
staticPage = section.find('input:radio[value="page"]'),
selects = section.find('select'),
check_disabled = function(){
selects.prop( 'disabled', ! staticPage.prop('checked') );
};
check_disabled();
section.find('input:radio').change(check_disabled);
});
//]]>
</script>
<?php
}
add_action('admin_head', 'add_js');

add_contextual_help($current_screen,
'<p>' . __('This screen contains the settings that affect the display of your content.') . '</p>' .
'<p>' . sprintf(__('You can choose what&#8217;s displayed on the front page of your site. It can be posts in reverse chronological order (classic blog), or a fixed/static page. To set a static home page, you first need to create two <a href="%s">Pages</a>. One will become the front page, and the other will be where your posts are displayed.'), 'post-new.php?post_type=page') . '</p>' .
'<p>' . __('You can also control the display of your content in RSS feeds, including the maximum numbers of posts to display, whether to show full text or a summary, and the character set encoding.') . '</p>' .
'<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>' .
'<p><strong>' . __('For more information:') . '</strong></p>' .
'<p>' . __('<a href="http://codex.wordpress.org/Settings_Reading_Screen" target="_blank">Documentation on Reading Settings</a>') . '</p>' .
'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
);

include( './admin-header.php' );
?>

<div class="wrap">
<?php screen_icon(); ?>
<h2><?php echo esc_html( $title ); ?></h2>

<form name="form1" method="post" action="options.php">
<?php settings_fields( 'reading' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th>
<td>
<input name="posts_per_page" type="text" id="posts_per_page" value="<?php form_option( 'posts_per_page' ); ?>" class="small-text" /> <?php _e( 'posts' ); ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="posts_per_rss"><?php _e( 'Syndication feeds show the most recent' ); ?></label></th>
<td><input name="posts_per_rss" type="text" id="posts_per_rss" value="<?php form_option( 'posts_per_rss' ); ?>" class="small-text" /> <?php _e( 'items' ); ?></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'For each article in a feed, show' ); ?> </th>
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'For each article in a feed, show' ); ?> </span></legend>
<p><label><input name="rss_use_excerpt" type="radio" value="0" <?php checked( 0, get_option( 'rss_use_excerpt' ) ); ?> /> <?php _e( 'Full text' ); ?></label><br />
<label><input name="rss_use_excerpt" type="radio" value="1" <?php checked( 1, get_option( 'rss_use_excerpt' ) ); ?> /> <?php _e( 'Summary' ); ?></label></p>
</fieldset></td>
</tr>

<tr valign="top">
<th scope="row"><label for="blog_charset"><?php _e( 'Encoding for pages and feeds' ); ?></label></th>
<td><input name="blog_charset" type="text" id="blog_charset" value="<?php form_option( 'blog_charset' ); ?>" class="regular-text" />
<span class="description"><?php _e( 'The <a href="http://codex.wordpress.org/Glossary#Character_set">character encoding</a> of your site (UTF-8 is recommended, if you are adventurous there are some <a href="http://en.wikipedia.org/wiki/Character_set">other encodings</a>)' ); ?></span></td>
</tr>
<?php do_settings_fields( 'reading', 'default' ); ?>
</table>

<?php do_settings_sections( 'reading' ); ?>

<?php submit_button(); ?>
</form>
</div>
<?php include( './admin-footer.php' ); ?>


Gabriel Reguly comments:

Hi RNWest,

Sorry, but how my answer does not work for you?

What is your WordPress version?

The functions.php code prevents the updating of the fields, so despite the fact that they are shown at options-reading.php, those fields are harmless now (in the lack of a better wording ;-)

And albeit editing core files is not the best approach, surely using my edited version those fields do not appear anymore. (Perhaps I could have only commented out the code, instead of removing the fields)

I have tested with WordPress 3.3 latest version, with multisite enabled.

Regards,
Gabriel

P.S. Thanks for increasing the prize.
Also thanks for sharing the fact that WP Questions charges a second 90 cents tax.


Gabriel Reguly comments:

Hi RNWest,

Could you confirm that you abandoned the question?

Don't you want to try my solution?

Regards,
Gabriel


RNWest comments:

Hi

Sorry got busy on other things,,

Yes, Gabriel your answers works but it was my fault for not being clear on my request.. I need to "Hide" this feature so the client will not see it..

Thanks


Gabriel Reguly comments:

Hi RNWest,

Sorry, but does not my edited version of wp-admin/options-reading.php hides the Front page displays choice?

Please see attached image for clarification.

(And forgive me the Brazilian Portuguese :P )

Regards,
Gabriel