Differenze tra le versioni di "Shortcode personalizzati WordPress"
(Creata pagina con "← ritorno == Vedia nche ... == * Funzioni personalizzate WordPress") |
m |
||
| (2 versioni intermedie di uno stesso utente non sono mostrate) | |||
| Riga 1: | Riga 1: | ||
| − | [[ | + | [[WordPress|← ritorno a WordPress]] [[Category:WordPress]] |
| − | == | + | == Vedi anche ... == |
| − | * [[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 attuale delle 07:35, 30 mar 2023
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' );