我认为这里的根本问题是shortcodes are not evaluated when placed inside HTML attributes. 您可以使用PHP和do_shortcode( \'[urlparam param="Book" /]\')
作为替代方法:
<!-- Calendly inline widget begin -->
<div class="calendly-inline-widget" data-url="<?php echo do_shortcode( \'[urlparam param="Book" /]\' ); ?>" style="min-width:320px;height:580px;"></div>
<script type="text/javascript" src="https://assets.calendly.com/assets/external/widget.js"></script>
<!-- Calendly inline widget end -->
Creating a plugin that contains a Calendly widget
另一种方法是创建一个输出所需HTML的小部件。
然后,通过将下面的代码保存到名为wpse-calendly.php
在名为wpse-calendly
. 然后,将自定义Calendally插件复制到plugins
目录,激活插件,并将小部件添加到所需的小部件区域。
请注意,此解决方案仍然依赖于urlparam
功能正常的短代码。
/**
* Register WPSE_Calendly widget.
*/
add_action( \'widgets_init\', \'wpse_register_calendly_widget\' );
function wpse_register_calendly_widget() {
register_widget( \'WPSE_Calendly_Widget\' );
}
/**
* Adds WPSE_Calendly widget.
*/
/**
* Core class used to implement a WPSE Calendly widget.
*
* @see WP_Widget
*/
class WPSE_Calendly_Widget extends WP_Widget {
/**
* Sets up a new WPSE Calendly widget instance.
*/
public function __construct() {
$widget_ops = array(
\'description\' => __( \'Display Calendly Widget.\', \'wpse_calendly\' ),
);
parent::__construct( \'wpse_calendly\', __( \'Calendly\', \'wpse_calendly\' ), $widget_ops );
}
/**
* Outputs the content for the current Calendly widget instance.
*
* @param array $args Display arguments including \'before_title\', \'after_title\',
* \'before_widget\', and \'after_widget\'.
* @param array $instance Settings for the current Calendly widget instance.
*/
public function widget( $args, $instance ) {
if ( ! empty( $instance[\'title\'] ) ) {
$title = $instance[\'title\'];
}
// Bail if the urlparam shortcode has not been registered.
if ( ! shortcode_exists( \'urlparam\' ) ) {
return;
}
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( \'widget_title\', $title, $instance, $this->id_base );
echo $args[\'before_widget\'];
if ( $title ) {
echo $args[\'before_title\'] . $title . $args[\'after_title\'];
}
?>
<!-- Calendly inline widget begin -->
<div class="calendly-inline-widget" data-url="<?php echo do_shortcode( \'[urlparam param="Book" /]\' ); ?>" style="min-width:320px;height:580px;"></div>
<script type="text/javascript" src="https://assets.calendly.com/assets/external/widget.js"></script>
<!-- Calendly inline widget end -->
<?php
echo $args[\'after_widget\'];
}
/**
* Handles updating settings for the current Calendly widget instance.
*
* @param array $new_instance New settings for this instance as input by the user via
* WP_Widget::form().
* @param array $old_instance Old settings for this instance.
* @return array Settings to save or bool false to cancel saving.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance[\'title\'] = sanitize_text_field( $new_instance[\'title\'] );
return $instance;
}
/**
* Outputs the Calendly widget settings form.
*
* @param array $instance Current settings.
*/
public function form( $instance ) {
$title_id = $this->get_field_id( \'title\' );
$instance[\'title\'] = ! empty( $instance[\'title\'] ) ? esc_attr( $instance[\'title\'] ) : \'\';
echo \'<p><label for="\' . $title_id .\'">\' . __( \'Title:\', \'wpse_calendly\' ) . \'</label>
<input type="text" class="widefat" id="\' . $title_id .\'" name="\' . $this->get_field_name( \'title\' ) .\'" value="\' . $instance[\'title\'] .\'" />
</p>\';
}
}