Title: Default subtitle value
Last modified: January 25, 2022

---

# Default subtitle value

 *  Resolved [webfantastic](https://wordpress.org/support/users/webfantastic/)
 * (@webfantastic)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/default-subtitle-value/)
 * Please tell me how to add a value to the default subtitle field so that it is
   not empty if the manager forgot to write it there. For example, I need the title
   to be substituted there by default.

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * (@helgatheviking)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/default-subtitle-value/#post-15289120)
 * You could use conditional logic…
 *     ```
       if ( function_exists('get_the_subtitle') && get_the_subtitle() ) {
          the_subtitle();
       } else {
          the_title();
       }
       ```
   
 *  Thread Starter [webfantastic](https://wordpress.org/support/users/webfantastic/)
 * (@webfantastic)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/default-subtitle-value/#post-15289202)
 * Does not work. I tried to broadcast the subtitle to another plugin, but if the
   field is not filled in, it doesn’t show the title instead. How can I put the 
   default value from title in the subtitle field itself when creating a product
   or article?
 *  Plugin Author [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * (@helgatheviking)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/default-subtitle-value/#post-15289321)
 * I don’t know exactly what you mean by broadcasting the subtitle to another plugin,
   but if you can share the subtitle you should be able to wrap it in conditional
   logic to check if it exists first.
 * You might also be able to run something on `save_post` to save a value if none
   exists. I don’t really like this as it saves a bunch of default texts to the 
   database, but it might do the trick, and is the best I can do.
 *     ```
       /**
        * Save a default Subtitle if none exists
        * 
        * @param  int $post_id the ID of the post we're saving
        * @return int
        */
       function kia_save_default_subtitle( $post_id ) {
           $subtitle = get_post_meta( $post_id, 'kia_subtitle', true );
           if ( $ subtitle ) {
               $default = esc_html__( 'A default subtitle', 'your-textdomain' );
               update_post_meta( $post_id, 'kia_subtitle', $default );
           }
       }
       add_action( 'save_post', 'kia_save_default_subtitle', 20 );
       ```
   
 * `
    -  This reply was modified 4 years, 4 months ago by [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/).
 *  Thread Starter [webfantastic](https://wordpress.org/support/users/webfantastic/)
 * (@webfantastic)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/default-subtitle-value/#post-15289457)
 * Thank you, I only need this for groceries. I’ll try this option.
 *  Thread Starter [webfantastic](https://wordpress.org/support/users/webfantastic/)
 * (@webfantastic)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/default-subtitle-value/#post-15300207)
 * Can you tell me how to do this only for products? Is there a filter for this,
   or do I need to disable all the other subtitle in the plugin settings?
 *  Plugin Author [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * (@helgatheviking)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/default-subtitle-value/#post-15300236)
 * In theory, I think you could save on `save_post_product`… see: [https://developer.wordpress.org/reference/hooks/save_post_post-post_type/](https://developer.wordpress.org/reference/hooks/save_post_post-post_type/)
 *     ```
       /**
        * Save a default Subtitle if none exists
        * 
        * @param  int $post_id the ID of the post we're saving
        * @return int
        */
       function kia_save_default_subtitle( $post_id ) {
           $subtitle = get_post_meta( $post_id, 'kia_subtitle', true );
           if ( $ subtitle ) {
               $default = esc_html__( 'A default subtitle', 'your-textdomain' );
               update_post_meta( $post_id, 'kia_subtitle', $default );
           }
       }
       add_action( 'save_post_product', 'kia_save_default_subtitle', 20 );
       ```
   
 * `
 *  Thread Starter [webfantastic](https://wordpress.org/support/users/webfantastic/)
 * (@webfantastic)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/default-subtitle-value/#post-15303359)
 * I tried, but it doesn’t work
 *  Plugin Author [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * (@helgatheviking)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/default-subtitle-value/#post-15303712)
 * Sorry, that’s the best I can offer. Though I did just notice that
 *     ```
       if ( $ subtitle ) {
       ```
   
 * should be
 *     ```
       if ( $subtitle ) {
       ```
   
 * Don’t know if that resolves your issue though. Alternatively, you could write
   additional conditional logic. With the post ID you can `get_post_type( $post_id)`
   and maybe use something like that.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Default subtitle value’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/kia-subtitle_f6f5f6.svg)
 * [KIA Subtitle](https://wordpress.org/plugins/kia-subtitle/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/kia-subtitle/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/kia-subtitle/)
 * [Active Topics](https://wordpress.org/support/plugin/kia-subtitle/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/kia-subtitle/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/kia-subtitle/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [HelgaTheViking](https://wordpress.org/support/users/helgatheviking/)
 * Last activity: [4 years, 4 months ago](https://wordpress.org/support/topic/default-subtitle-value/#post-15303712)
 * Status: resolved