$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>customization - Add attribute to existing Shortcode|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

customization - Add attribute to existing Shortcode

matteradmin10PV0评论

I have an existing shortcode (from a plugin) and I would like to add a new attribute or parameter to this shortcode.

The shortcode looks like this:

[my_shortcode_from_plugin_xyz posts="5" autoplay="true"]

Is it possible to add a new attribute like => url=""?

This is working, but I can't get the attribute from the shortcode itself:

[my_shortcode_from_plugin_xyz posts="5" autoplay="true" url=""]

function do_something( $atts ) {      
    $atts['siteurl'] = '';

return $atts;
}
add_filter( 'shortcode_atts_recent_post_slider', 'do_something', 10, 3 );

I also tried to set the defaults like this:

$atts = shortcode_atts( [
    'siteurl' => '',
  ], $atts  );

The plugIn code to create the shortcode:

function wprpsp_recent_post_slider( $atts, $content = null ) {


$atts = shortcode_atts(array(
    'post_type'             => 'post',
    'taxonomy'              => 'category',
    'limit'                 => 20,
    'category'              => '',
    'include_cat_child'     => 'true',
    'design'                => 'design-1',
    'show_date'             => 'true',
    'show_category_name'    => 'true',
    'show_content'          => 'true',
    'show_author'           => 'true',
    'content_words_limit'   => 20,
    'fade'                  => 'false',
    'content_tail'          => '...',
    'dots'                  => 'true',
    'arrows'                => 'true',
    'autoplay'              => 'true',
    'autoplay_interval'     => 3000,
    'speed'                 => 600,
    'loop'                  => 'true',
    'nav_slides'            => 4,
    'rtl'                   => '',
    'link_target'           => 'self',
    'show_read_more'        => 'true',
    'read_more_text'        => '',
    'order'                 => 'DESC',
    'orderby'               => 'date',
    'exclude_cat'           => array(),
    'hide_post'             => array(),
    'posts'                 => array(),
    'include_author'        => array(),
    'exclude_author'        => array(),
    'slider_height'         => '',
    'sticky_posts'          => 'false',
    'image_size'            => 'full',
    'image_fit'             => 'true',
    'query_offset'          => '',
    'extra_class'           => '',
    ), $atts, 'recent_post_slider');

$supported_post_types           = wprpsp_get_option( 'post_types',array() );
    $shortcode_designs              = wprpsp_recent_post_slider_designs();
    $atts['content_tail']           = html_entity_decode( $atts['content_tail'] );
    $atts['post_type']              = ( !empty( $atts['post_type'] ) && in_array( $atts['post_type'], $supported_post_types ) ) ? $atts['post_type'] : 'post';
    $atts['taxonomy']               = ( !empty( $atts['taxonomy'] ) )               ? $atts['taxonomy']                             : 'category';
    $atts['limit']                  = !empty( $atts['limit'] )                      ? $atts['limit']                                : 20;
    $atts['category']               = ( !empty( $atts['category'] ) )               ? explode( ',',$atts['category'] )              : '';
    $atts['include_cat_child']      = ( $atts['include_cat_child'] == 'false' )     ? false                                         : true;
    $atts['design']                 = ( $atts['design'] && ( array_key_exists( trim( $atts['design'] ), $shortcode_designs ) ) ) ? trim( $atts['design'] ) : 'design-1';
    $atts['show_date']              = ( $atts['show_date'] == 'false' )             ? 0                                             : 1;
    $atts['show_category_name']     = ( $atts['show_category_name'] == 'false' )    ? 0                                             : 1;
    $atts['show_content']           = ( $atts['show_content'] == 'false' )          ? 0                                             : 1;
    $atts['show_author']            = ( $atts['show_author'] == 'false' )           ? 0                                             : 1;
    $atts['content_words_limit']    = !empty( $atts['content_words_limit'] )        ? $atts['content_words_limit']                  : 20;
    $atts['fade']                   = ( $atts['fade'] == 'false' )                  ? 'false'                                       : 'true';
    $atts['dots']                   = ( $atts['dots'] == 'false' )                  ? 'false'                                       : 'true';
    $atts['arrows']                 = ( $atts['arrows'] == 'false' )                ? 'false'                                       : 'true';
    $atts['autoplay']               = ( $atts['autoplay'] == 'false' )              ? 'false'                                       : 'true';
    $atts['autoplay_interval']      = !empty( $atts['autoplay_interval'] )          ? $atts['autoplay_interval']                    : 3000;
    $atts['speed']                  = !empty( $atts['speed'] )                      ? $atts['speed']                                : 600;
    $atts['infinite']               = ( $atts['loop'] == 'true' )                   ? 'true'                                        : 'false';
    $atts['nav_slides']             = !empty( $atts['nav_slides'] )                 ? $atts['nav_slides']                           : 4;
    $atts['link_target']            = ( $atts['link_target'] == 'blank')            ? '_blank'                                      : '_self';
    $atts['show_read_more']         = ( $atts['show_read_more'] == 'false' )        ? 0                                             : 1;
    $atts['order']                  = (strtolower( $atts['order'] ) == 'asc' )      ? 'ASC'                                         : 'DESC';
    $atts['orderby']                = !empty( $atts['orderby'] )                    ? $atts['orderby']                              : 'date';
    $atts['exclude_cat']            = !empty( $atts['exclude_cat'] )                ? explode( ',', $atts['exclude_cat'] )          : array();
    $atts['hide_post']              = !empty( $atts['hide_post'] )                  ? explode( ',', $atts['hide_post'] )            : array();
    $atts['posts']                  = !empty( $atts['posts'] )                      ? explode( ',', $atts['posts'] )                : array();
    $atts['include_author']         = !empty( $atts['include_author'] )             ? explode( ',', $atts['include_author'] )       : array();
    $atts['exclude_author']         = !empty( $atts['exclude_author'] )             ? explode( ',', $atts['exclude_author'] )       : array();
    $atts['read_more_text']         = !empty( $atts['read_more_text'] )             ? $atts['read_more_text']                       : __('Read More', 'wp-responsive-recent-post-slider');
    $atts['slider_height']          = ( !empty( $atts['slider_height'] ) )          ? $atts['slider_height']                        : '';
    $atts['slider_height_css']      = ( !empty( $atts['slider_height'] ) )          ? "style='height:{$atts['slider_height']}px;'"  : '';
    $atts['sticky_posts']           = ( $atts['sticky_posts'] == 'true' )           ? false                                         : true;
    $atts['image_size']             = !empty( $atts['image_size'] )                 ? $atts['image_size']                           : 'full';
    $atts['image_fit']              = ( $atts['image_fit'] == 'false' )             ? 0                                             : 1;
    $atts['query_offset']           = !empty( $atts['query_offset'] )               ? $atts['query_offset']                         : null;
    $atts['extra_class']            = wprpsp_pro_sanitize_html_classes( $atts['extra_class'] );

    // Extract Shortcode Var
    extract($atts);

Puhh, I'm completely stuck ...

BR, P

Post a comment

comment list (0)

  1. No comments so far