Differenze tra le versioni di "Shortcode personalizzati WordPress"
| Riga 3: | Riga 3: | ||
== Vedi anche ... == | == Vedi anche ... == | ||
* [[Funzioni personalizzate WordPress|Funzioni personalizzate WordPress →]] | * [[Funzioni personalizzate WordPress|Funzioni personalizzate WordPress →]] | ||
| + | |||
| + | |||
| + | == Includere il contenuto di una pagina in un'altra pagina o area di testo == | ||
| + | <pre> | ||
| + | /** | ||
| + | * SHORTCODE per includere il contenuto di una pagina in un'altra pagina o area di testo; | ||
| + | * shortcode da inserire: [myshrt_postcontent id=""] | ||
| + | */ | ||
| + | function myshrt_postcontent_func( $atts ) { | ||
| + | if( ! array_key_exists( 'id', $atts ) ) | ||
| + | return ''; | ||
| + | if( empty( $atts['id'] ) ) | ||
| + | return ''; | ||
| + | $content_post = get_post( $atts['id'] ); | ||
| + | if( empty( $content_post ) ) | ||
| + | return ''; | ||
| + | $content = apply_filters('the_content', $content_post->post_content ); | ||
| + | $content = str_replace(']]>', ']]>', $content); | ||
| + | return $content; | ||
| + | } | ||
| + | add_shortcode( 'myshrt_postcontent', 'myshrt_postcontent_func' ); | ||
| + | </pre> | ||
Versione delle 07:23, 22 ott 2021
Vedi anche ...
Includere il contenuto di una pagina in un'altra pagina o area di testo
/**
* SHORTCODE per includere il contenuto di una pagina in un'altra pagina o area di testo;
* shortcode da inserire: [myshrt_postcontent id=""]
*/
function myshrt_postcontent_func( $atts ) {
if( ! array_key_exists( 'id', $atts ) )
return '';
if( empty( $atts['id'] ) )
return '';
$content_post = get_post( $atts['id'] );
if( empty( $content_post ) )
return '';
$content = apply_filters('the_content', $content_post->post_content );
$content = str_replace(']]>', ']]>', $content);
return $content;
}
add_shortcode( 'myshrt_postcontent', 'myshrt_postcontent_func' );