Skip to content

Instantly share code, notes, and snippets.

@dantetesta
Last active May 13, 2023 00:22
Show Gist options
  • Save dantetesta/f7e5b0bf7c5bde5c956dfa03dbfaa7f2 to your computer and use it in GitHub Desktop.
Save dantetesta/f7e5b0bf7c5bde5c956dfa03dbfaa7f2 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Text to HTML
Description: Converte um texto em HTML usando um shortcode [text_to_html field="nome_do_campo_meta"]
Version: 1.0
Author: Dante Testa
*/
function text_to_html_shortcode( $atts ) {
$atts = shortcode_atts( array(
'post_id' => get_the_ID(),
'field' => '',
), $atts, 'text_to_html' );
$meta_value = get_post_meta( $atts['post_id'], $atts['field'], true );
// Trata parágrafos e quebras de linha
$meta_value = wpautop( $meta_value );
// Imprime o valor do metafield
return $meta_value;
}
add_shortcode( 'text_to_html', 'text_to_html_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment