I think the underlying issue here is that shortcodes are not evaluated when placed inside HTML attributes. You could modify the template and output the necessary HTML using PHP and do_shortcode( '[urlparam param="Book" /]')
as an alternative approach:
<!-- 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
Another approach is to create a widget that outputs the desired HTML.
The code below can then be wrapped into a plugin by saving it to a file named wpse-calendly.php
in a directory named wpse-calendly
. Then, copy our custom Calendly plugin into the plugins
directory, activate the plugin, and add the widget to the desired widget area.
Note that this solution still relies on the urlparam
shortcode to function properly.
/**
* 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>';
}
}