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

Changing the WP tagline from a theme options page WordPress

  • SOLVED

Hello,

Using the (Automattic) `_s` theme as an example to create my own theme options page,
would it perhaps be possible to add a text field which matches the WP (default) tagline/description? (making it back-and-forward updatable between `options-general.php` and `themes.php?page=theme_options`)

Here's the code from the theme options page I'm currently using: http://pastebin.com/fFFcVTSU

Best regards,

Cor

Answers (1)

2012-05-30

John Cotton answers:

Hi Cor

Do you mean have someone enter a value on your page and that value get set as the site description (and appear on the General settings page if they visit there). And if they update the General settings page and update, that update is reflected in the value you display on your page?

If so, the short answer is yes, but not with the settings API as you are using it since that will send the values to rows other that the blogdescription value (which is the one you need).

If the above is what you want, I can give you some pointers for the code.


cor comments:

Hi John,

The short answer would indeed be 'yes'.

Being just beyond novice php-wise, any pointers would be more than appreciated.


John Cotton comments:

It's not very pretty, and I haven't actually tried the code, but I think this should work:


function _s_theme_options_render_page() {

// This is new - need to get the current value
$tagline = get_option('blogdescription ');

?>
<div class="wrap">
<?php screen_icon(); ?>
<?php $theme_name = function_exists( 'wp_get_theme' ) ? wp_get_theme() : get_current_theme(); ?>
<h2><?php printf( __( '%s Theme Options', '_s' ), $theme_name ); ?></h2>
<?php settings_errors(); ?>

<form method="post" action="options.php">
<?php
settings_fields( '_s_options' );
do_settings_sections( 'theme_options' );
// Here's the change:
echo sprintf('<input type="text" name="txtBlogInfo" value="%s" />', $tagline);
// You could put some styling and prompts around this if you wanted to...

submit_button();
?>
</form>
</div>
<?php
}

function _s_theme_options_validate( $input ) {
$output = array();

// This is new: gets the contents of the postback and sticks it into the database
update_option( 'blogdescription ', $_POST['txtBlogInfo'] );

// The sample text input must be safe text with no HTML tags
if ( isset( $input['sample_text_input'] ) && ! empty( $input['sample_text_input'] ) )
$output['sample_text_input'] = wp_filter_nohtml_kses( $input['sample_text_input'] );

// The sample textarea must be safe text with the allowed tags for posts
if ( isset( $input['sample_textarea'] ) && ! empty( $input['sample_textarea'] ) )
$output['sample_textarea'] = wp_filter_post_kses( $input['sample_textarea'] );

return apply_filters( '_s_theme_options_validate', $output, $input );
}


cor comments:

Hi John,

Still figuring out on how to implement this best, but yours is definitely the right answer.

Again, much appreciated!