WPIntell

Source evidence

Default subtitle value

KIA Subtitle · support · 2022-01-25T14:12:00+00:00

mixedsentiment
mediumseverity
0.84relevance
8replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

1 / 15 rows with source links

6.7% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

14 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
webfantastic resolved
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. You could use conditional logic… if ( function_exists('get_the_subtitle') && get_the_subtitle() ) { the_subtitle(); } else { the_title(); } 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? 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 . Thank you, I only need this for groceries. I’ll try this option. 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? In theory, I think you could save on save_post_product … see: 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 ); ` I tried, but it doesn’t work 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.

Comments

8 shown
HelgaTheViking 2022-01-25T15:59:00+00:00

You could use conditional logic… if ( function_exists('get_the_subtitle') && get_the_subtitle() ) { the_subtitle(); } else { the_title(); }

webfantastic 2022-01-25T16:21:00+00:00

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?

HelgaTheViking 2022-01-25T16:46:00+00:00

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 .

webfantastic 2022-01-25T17:18:00+00:00

Thank you, I only need this for groceries. I’ll try this option.

webfantastic 2022-01-28T00:01:00+00:00

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?

HelgaTheViking 2022-01-28T00:27:00+00:00

In theory, I think you could save on save_post_product … see: 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 ); `

webfantastic 2022-01-28T17:27:00+00:00

I tried, but it doesn’t work

HelgaTheViking 2022-01-28T19:09:00+00:00

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.