Modify Shortcode Alert

Hi Support-Team,

i was wondering how i can modify the alert shortcode in a way that the heading is not a “h6” heading but a “h3” heading or maybe just a “div”. My idea was to put this code in my child`s theme function,php:

// Alert
// =============================================================================

function x_shortcode_alert2( $atts, $content = null ) {
  extract( shortcode_atts( array(
    'id'      => '',
    'class'   => '',
    'style'   => '',
    'type'    => '',
    'heading' => '',
    'close'   => ''
  ), $atts, 'x_alert' ) );

  $id      = ( $id      != '' ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class   = ( $class   != '' ) ? 'x-alert ' . esc_attr( $class ) : 'x-alert';
  $style   = ( $style   != '' ) ? 'style="' . $style . '"' : '';
  $type    = ( $type    != '' ) ? ' x-alert-' . $type : '';
  $heading = ( $heading != '' ) ? $heading = '<h3 class="h-alert">' . $heading . '</h3>' : $heading = '';
  if ( $close == 'true' ) {
    $close = ' fade in';
    $close_btn = '<button type="button" class="close" data-dismiss="alert">&times;</button>';
  } else {
    $close = ' x-alert-block';
    $close_btn = '';
  }

  $output = "<div {$id} class=\"{$class}{$type}{$close}\" {$style}>{$close_btn}{$heading}" . do_shortcode( $content ) . "</div>";

  return $output;
}

add_filter('init', function() {
   remove_shortcode( 'x_shortcode_alert' );

   add_shortcode( 'x_alert', 'x_shortcode_alert2' );
});

But somehow it doesn`t work. Do you have a clue or another way to solve this?

Many Thanks

Hi,

Please change your code to this.

// Alert
// =============================================================================

function x_shortcode_alert2( $atts, $content = null ) {
  extract( shortcode_atts( array(
    'id'      => '',
    'class'   => '',
    'style'   => '',
    'type'    => '',
    'heading' => '',
    'close'   => ''
  ), $atts, 'x_alert' ) );

  $id      = ( $id      != '' ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class   = ( $class   != '' ) ? 'x-alert ' . esc_attr( $class ) : 'x-alert';
  $style   = ( $style   != '' ) ? 'style="' . $style . '"' : '';
  $type    = ( $type    != '' ) ? ' x-alert-' . $type : '';
  $heading = ( $heading != '' ) ? $heading = '<h3 class="h-alert">' . $heading . '</h3>' : $heading = '';
  if ( $close == 'true' ) {
    $close = ' fade in';
    $close_btn = '<button type="button" class="close" data-dismiss="alert">&times;</button>';
  } else {
    $close = ' x-alert-block';
    $close_btn = '';
  }

  $output = "<div {$id} class=\"{$class}{$type}{$close}\" {$style}>{$close_btn}{$heading}" . do_shortcode( $content ) . "</div>";

  return $output;
}

add_filter('init', function() {
   remove_shortcode( 'x_shortcode_alert' );

   add_shortcode( 'x_shortcode_alert', 'x_shortcode_alert2' );
});

Hope that helps

Hi Paul,

thank you! Unfortunately its still an “h6” heading. Even if I modifiy the alert.php itself in the x conerstone > includes > shortcodes folder it doesnt work. Other edits in relation to shortcodes, e.g. the promo shortcode, are working. Do you have any other suggestions?

Hi there,

The h6 tag is actually hard coded in the element file that you can find in wp-content/plugins/cornerstone/includes/elements/classic/alert/shortcode.php

You could find the line: $heading = ( $heading ) ? "<h6 class=\"h-alert\">{$heading}</h6>" : '';

What you can try to do is to create a custom Cornerstone element which is a copy of the classic alert element then do the edits from there.

Hope this helps.

Thanks, i`ll try that

Let us know how it goes,

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.