Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Differnt Site Title and Tagline per Page WordPress Theme

alchymyth Mar 31st, 2018 (edited) 169 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. /*
  2. * customize different Site Title
  3. * and Tagline per (static) page
  4. */
  5.  
  6. // create meta boxe for 'Custom Site Title' field below page editor
  7.  
  8. add_action( 'admin_menu', 'custom_site_title' );
  9. add_action( 'save_post', 'save_custom_site_title' );
  10.  
  11. function custom_site_title() {
  12.     add_meta_box( 'custom_site_title', 'Custom Site Title for this page <small>(if left empty, the general Site Title will be used)</small>', 'custom_site_title_input_function', 'page', 'normal', 'high' );
  13. }
  14.  
  15. function custom_site_title_input_function() {
  16.     global $post;
  17.     echo '<input type="hidden" name="custom_site_title_input_hidden" id="custom_site_title_input_hidden" value="'.wp_create_nonce( 'custom_site_title-nonce' ).'" />';
  18.     echo '<input type="text" name="custom_site_title_input" id="custom_site_title_input" style="width:100%;" value="'.get_post_meta( $post->ID, '_custom_site_title', true ).'" />';
  19. }
  20.  
  21. function save_custom_site_title( $post_id ) {
  22.     if (isset( $_POST['custom_site_title_input_hidden'] )) if (!wp_verify_nonce($_POST['custom_site_title_input_hidden'], 'custom_site_title-nonce')) return $post_id;
  23.     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
  24.     if (isset( $_POST['custom_site_title'] )) {
  25.         $customSiteTitle = $_POST['custom_site_title_input'];
  26.         update_post_meta( $post_id, '_custom_site_title', $customSiteTitle );
  27.     }
  28. }
  29.  
  30. // create meta boxe for 'Custom Tagline' field below page editor
  31.  
  32. add_action( 'admin_menu', 'custom_site_tagline' );
  33. add_action( 'save_post', 'save_custom_site_tagline' );
  34.  
  35. function custom_site_tagline() {
  36.     add_meta_box( 'custom_site_tagline', 'Custom Tagline for this page <small>(if left empty, the general Tagline will be used)</small>', 'custom_site_tagline_input_function', 'page', 'normal', 'high' );
  37. }
  38.  
  39. function custom_site_tagline_input_function() {
  40.     global $post;
  41.     echo '<input type="hidden" name="custom_site_tagline_input_hidden" id="custom_site_tagline_input_hidden" value="'.wp_create_nonce( 'custom_site_tagline-nonce' ).'" />';
  42.     echo '<input type="text" name="custom_site_tagline_input" id="custom_site_tagline_input" style="width:100%;" value="'.get_post_meta( $post->ID, '_custom_site_tagline', true ).'" />';
  43. }
  44.  
  45. function save_custom_site_tagline( $post_id ) {
  46.     if (isset( $_POST['custom_site_tagline_input_hidden'] )) if (!wp_verify_nonce($_POST['custom_site_tagline_input_hidden'], 'custom_site_tagline-nonce')) return $post_id;
  47.     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
  48.     if (isset( $_POST['custom_site_tagline'] )) {
  49.         $customSiteTagline = $_POST['custom_site_tagline_input'];
  50.         update_post_meta( $post_id, '_custom_site_tagline', $customSiteTagline );
  51.     }
  52. }
  53.  
  54. //preparing the output
  55.  
  56. add_filter( 'bloginfo', 'custom_site_title_tagline_output', 2, 10 );
  57.  
  58. function custom_site_title_tagline_output( $site_bloginfo, $show ) {
  59.     global $post;
  60.     if( $show == 'name' && is_page() && get_post_meta( $post->ID, '_custom_site_title', true ) ) {
  61.         $site_bloginfo = get_post_meta( $post->ID, '_custom_site_title', true );
  62.     }
  63.     if( $show == 'description' && is_page() && get_post_meta( $post->ID, '_custom_site_tagline', true ) ) {
  64.         $site_bloginfo = get_post_meta( $post->ID, '_custom_site_tagline', true );
  65.     }
  66.     return $site_bloginfo;
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top