KIA Subtitle

Descrizione

KIA subtitle allows you to add a subtitle to your posts and retrieve it in the loop in the same manner as the post title. By using the Subtitle block or the the_subtitle() or get_the_subtitle() template tags.

It adds an input field right under the title field of posts, pages and any custom post type. It also add a subtitle column to the edit screen as well as to the quick edit.

You can also use the Subtitle block or the shortcode [the-subtitle] to display it within the post content.

Site Editor

The plugin provides a Subtitle block in the editor. In the post editor, this doesn’t make a lot of sense, but mimics the core Title block. The ideal use case for the Subtitle block is when editing your theme

  1. Click Edit Site in the WordPress toolbar
  2. Select the template you wish to edit, commonly this might be called Single Post, or Singular.
  3. Insert the Subtitle block where needed, commonly right after the Title block.

Template Tags

This plugin does not attempt to output the subtitle. With an infinite number of themes, it is not possible for us to support that. The onus is on the user to customize their theme accordingly. The plugin provides two template tags that can be used to customize your theme as desired.

`the_subtitle( string $before

”, string $after = ”, bool $display = true ): void|string` =

Displays or retrieves the current post subtitle with optional markup.

Parameters

$before `string` `optional`
Markup to prepend to the title.
Default: `''`

$after `string` `optional`
Markup to append to the title.
Default: `''`

$display `bool` `optional`
Whether to echo or return the title. Default true for echo.
Default: `true`

Example usage:

if ( function_exists( 'the_subtitle' ) ) the_subtitle( '<h2 class="subtitle">', '</h2>' );

`get_the_subtitle( int|WP_Post $post ): string`

Retrieves the post subtitle.

Parameters

$post `int|WP_Post` `optional`
Post ID or WP_Post object.
Default: global `$post` object.

`

WooCommerce support

There is a small bridge plugin you can install and activate to automatically display the subtitle in most WooCommerce locations. This will work for all themes that are using WooCommerce’s default hooks.

NB: It’s known that the Ocean WP theme has it’s own hooks in the WooCommerce templates. You will need to alter the bridge plugin… please take a look at this support thread.

WPML Ready

KIA subtitle è stato verificato da WPML e ti permetterà di tradurre il sottotitolo nei siti multilingua.

Supporto

Il supporto è gestito nei forum di WordPress. Ricorda che questo tipo di supporto è limitato e non copre nessuna implementazione personalizzata del plugin.

Riporta ogni bug, errore, avviso, o problema con il codice su Github

Screenshot

  • This is what the input will look like in the Block Editor.
  • Insert a subtitle block into your block theme's template, such as the Singular template for displaying Posts.
  • This is what the input will look like in the Classic Editor.

Installazione

  1. Carica la cartella del plugin nella directory /wp-content/plugins/
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. For Block Themes: Add the subtitle block to your template in the Site Editor
  4. For Classic Themes: Add the ‘the_subtitle()’ tag to your theme

FAQ

Come faccio a mostrare il sottotitolo nel mio tema?

The intended way is with the the_subtitle() template tag as follows:

if ( function_exists( 'the_subtitle' ) ) the_subtitle();

Puoi aplicare alla stringa un markup utilizzando i parametri $before e $after

if ( function_exists( 'the_subtitle' ) ) the_subtitle( '<h2 class="subtitle">', '</h2>' );

As an absolute worst case fallback you could also add the following snippet to your functions.php in order to prepend the subtitle to the content.

/**
 * Prepend the subtitle to the post content. 
 *
 * @param string $content The post content
 * @return string
 */
function kia_prepend_subtitle_to_content( $content ) {
    if ( ! is_admin() ) {

        $subtitle = function_exists( 'get_the_subtitle' ) ? get_the_subtitle() : '';

        if ( ! empty( $subtitle ) ) {
            $content = '<h2 class="subtitle">' . wp_kses_post( $subtitle ) . '</h2>' . $content;
        }
    }
    return $content;
}
add_filter( 'the_content', 'kia_prepend_subtitle_to_content' );

You could also filter the_title and but it would have to be part of the post title’s markup and could not have it’s own markup as nesting header elements is invalid HTML markup.

/**
 * Append the subtitle to the title. 
 *
 * @param string $title The post title
 * @return string
 */
function kia_append_subtitle_to_title( $title ) {
    if ( ! is_admin() ) {
        $subtitle = function_exists( 'get_the_subtitle' ) ? get_the_subtitle() : '';

        if ( ! empty( $subtitle ) ) {
            $title .= ' &mdash; ' . wp_kses_post( $subtitle );
        }
    }
    return $title;
}
add_filter( 'the_title', 'kia_append_subtitle_to_title' );

Dove devo aggiungere questo codice?

Sfortunatamente, non posso indicarti esattamente in che file inserire il codice sopra riportato, per i motivi: 1. non so dove tu voglia mostrare il sottotitolo, e 2. ogni tema ha una struttura differente.

Ad ogni modo, generalmente, the_subtitle() è un template tag, e come tale vorrai metterlo in un file template. Probabilmente ciò che stai cercando è il file che contiene il loop degli articoli. Per la maggior parte dei temi tale file è single.php ( o page.php per le pagine ), ma in parecchi temi potrebbe anche essere content.php. Ammesso tu voglia visualizzare il sottotitolo subito dopo il tuo titolo principale, dovresti inserire il codice su riportato dopo:

<h1 class="entry-title"><?php the_title(); ?></h1>

As an example if you wanted to display the subtitle on standard single posts, in the Twenty Twenty theme you’d create a copy of the entry-header.php template in your child theme and modify it as shown in this gist

Come faccio a modificare lo stile del sottotitolo?

Se hai racchiuso il sottotitolo in un tag H2 con la classe subtitle come nel secondo esempio qui sopra, puoi personalizzarlo con lo stile che preferisci.

.subtitle { color: pink; }

Can I display the subtitle for my WooCommmerce products

Yes! You can use this bridge plugin to automatically display the subtitle in most WooCommerce locations.

Posso aggiungere il sottotitolo come Meta tag al Titolo della Pagina?

function kia_add_subtitle_to_wp_title( $title ) {
if ( is_single() && function_exists( ‘get_the_subtitle’ ) ) && $subtitle == get_the_subtitle( get_the_ID() ) ) {
$title .= $subtitle;
}
}
add_filter( ‘wp_title’, ‘kia_add_subtitle_to_wp_title’ );

Il plugin è pronto per la traduzione?

WPML adesso supporta KIA Subtitle!

Recensioni

5 Aprile 2024
We have been using this plugin for a while now, and it always works out of the box, there are some small modifications and css lines we added for it to do what we need. Its a really good plugin and the support from Helga is awesome! Hope to see this going for the decades to come!
7 Novembre 2021
Very useful plugin! Lightweight, easy to set up, I recommend this plugin! Thank you very much!
25 Febbraio 2021
It is a simple and very useful plugin that I have already used on more than one occasion. It works perfectly with several different themes. Currently used with Woocommerce on Avada theme and WordPress 5.6.2 Thank you very much
Leggi tutte le recensioni di 18

Contributi e sviluppo

“KIA Subtitle” è un software open source. Le persone che hanno contribuito allo sviluppo di questo plugin sono indicate di seguito.

Collaboratori

“KIA Subtitle” è stato tradotto in 5 lingue. Grazie ai traduttori per i loro contributi.

Traduci “KIA Subtitle” nella tua lingua.

Ti interessa lo sviluppo?

Esplora il codice segui il repository SVN, segui il log delle modifiche tramite RSS.

Changelog (registro delle modifiche)

4.0.0

  • Important: Requires WordPress 6.1
  • New: Subtitle block
  • New: Introduce kia_subtitle_sanitize_subtitle for adding your own custom sanitization rules.

3.0.3

  • Fix: Check subtitle is set before updating.

3.0.2

  • Fix: Do not load Gutenberg assets if CPT does not support ‘custom-fields’. Replace with fallback metabox.

3.0.1

  • Fix: Remove the duplicate metabox for post types using Classic Editor.

3.0.0

  • Add subtitle as a panel in the Gutenberg editor

2.0.0

  • Add subtitle as a metabox that is compatible with Gutenberg editor

1.6.8

  • Allargata la colonna dei prodotti WooCommerce

1.6.7

  • Aggiornato il link per le donazioni
  • Aggiornamenti necessari e verificati rispetto alle versioni
  • Corretta la posizione della colonna per i prodotti WooCommerce
  • Minificati gli script lato admin

1.6.6

  • Inserisce il sottotitolo dopo il titolo, oppure alla fine se il sottotitolo non esiste

1.6.5

  • Aggiunto wpml-config.xml per la compatibilità con WPML

1.6.4

  • Aggiunto link alle impostazioni del plugin
  • verificando con WP4.4

1.6.3

  • sistemato docblock

1.6.2

  • salva i sottotitoli per gli attachments. Sembra che gli attachments non eseguano l’hook save_post

1.6.1

  • risolti avvisi PHP in modalità strict-standards

1.6

  • utilizza una istanza KIA_Subtitle() piuttosto che una variabile globale

1.5.4

  • reinserito lo script per la modifica rapida, cancellato accidentalmente

1.5.4

  • rimosso uno script inutilizzato ora che l’input utilizza ‘segnaposto’
  • rimosso tabindex dall’input (non faceva nulla, ad ogni modo)
  • aggiunto script alla tab da titolo a sottotitolo, al contenuto. props @Giuseppe Mazzapica
  • aggiunto readme.md

1.5.3

  • verificata compatibilità con WP3.8
  • rimossa retrocompatibilità con hook edit_form_after_title
  • migliorato il docblock

1.5.2

  • Spostato il chancgelog nel readme.txt #facepalm

1.5.1

  • Impostata la funzione di convalida con quella meno restrittiva sanitize_post_field, che combacia con la forma di convalida utilizzata da WordPress per il titolo dell’articolo
  • Spostato il changelog in un file separato

1.5

  • Cambiate le opzioni in “seleziona per abilitare” invece di “seleziona per disabilitare” (tutti i post types sono abilitati di default)
  • Inclusa una routine di aggiornamento per cambiare tutte le vecchie opzioni nel nuovo formato
  • Aggiornata la FAQ con esempi per Twenty Twelve

1.4.3

  • Sistemato $args per get_post_types()
  • Corretta la logica condizionale difettosa per utenti senza post types esclusi

1.4.2

  • Sistemato $args per get_post_types()
  • cambiato il filtro ‘kia_subtitle_post_types’ filter in ‘kia_subtitle_post_type_args’

1.4.1

  • Sistemato $args per get_post_types()
  • aggiunto filtro ‘kia_subtitle_post_types’ alle opzioni del plugin

1.4

  • Aggiunta la possibilità di eswcludere il sottotitolo da determinati post types

1.3.4

  • Aggiunto filtro the_subtitle per consentire la modifica del contenuto del sottotitolo

1.3.3

  • Corretta notifica: proprietà indefinita
  • Ripulite le funzioni di enqueue per gli script

1.3.2

  • Correzione per retro-compatibilità

1.3.1

  • Aggiunti esempi di codice alle FAQ

1.3

  • Migliorata esclusione degli attributi HTML grazie a @nealpoole
  • Si avvale dei nuovi action hooks introdotti in WP 3.5

1.2

  • Imita the_title(), così the_subtitle() adesso accetta i parametri before, after e echo:
    the_subtitle( $before = '', $after = '', $echo = true )

1.1.2

  • Corretto riaggiornamento della modifica rapida ( al secondo click per su modifica rapida, il valore ancora corrispodeva all’originale )

1.1.1

  • Correzione per la possibilità di rimuovere il sottotitolo

1.1

  • Aggiunta colonna alla schermata edit.php
  • Aggiunto sottotitolo a modifica rapida
  • Caricare nuovamente lo script su edit.php

1.0.2

  • aggiornato link per le donazioni

1.0.1

  • Non caricare script sulla schermata edit.php

1.0

  • Rilascio iniziale.