// Función para obtener y mostrar el contenido externo con URL personalizada
// [mostrar_contenido_externo url="https://www.speedtest.net/es"]
function mostrar_contenido_externo_shortcode($atts) {
// Establecer los atributos por defecto del shortcode
$atts = shortcode_atts(array(
'url' => '',
), $atts);
// Verificar si se proporcionó una URL
if (empty($atts['url'])) {
return 'Por favor, proporciona una URL válida.';
}
// Recuperar el contenido HTML de la URL
$response = wp_remote_get($atts['url']);
if (is_array($response) && !is_wp_error($response)) {
// Obtener el contenido HTML de la respuesta
$html_content = wp_remote_retrieve_body($response);
// Modificar el contenido HTML para agregar estilos CSS
$html_content_with_css = '
' . $html_content . '
';
return $html_content_with_css;
} else {
return 'No se pudo obtener el contenido externo.';
}
}
add_shortcode('mostrar_contenido_externo', 'mostrar_contenido_externo_shortcode');