Support » Plugin: WordPress Shortcodes Plugin — Shortcodes Ultimate » Filter Button “noopener”

  • Resolved Antal Tettinger

    (@antaltettinger)


    Dear Vladimir,

    I have checked the docs and FAQ, but couldn’t figure out this issue.
    I am trying to modify the output so when an su_button is created the rel=”noopener” would be rel=”nofollow”.

    I have tried with this code in the functions.php but didn’t work:

    function add_custom_button_style($shortcodes) {

    $shortcodes[‘button’][‘atts’][‘rel’] = “nofollow”;

    return $shortcodes;

    }
    add_filter( ‘su/data/shortcodes’, ‘add_custom_button_style’ );

    I would really appreciate your help in this, we are using Shortcodes Ultimate on all our sites.

    Thanks,

    Antal

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Vova

    (@gn_themes)

    Hi Antal,

    use the following code in functions.php:

    add_filter( 'shortcode_atts_button', function( $out, $pairs, $atts, $shortcode ) {
    
      if ( ! isset( $atts['rel'] ) ) {
        $out['rel'] = 'noopener nofollow';
      }
    
      return $out;
    
    }, 10, 4 );

    As a result:

    [su_button]Button text[/su_button]
    Expands to: <a rel="noopener nofollow">
    
    [su_button rel="nofollow"]Button text[/su_button]
    Expands to: <a rel="nofollow">
    
    [su_button rel="noreferrer"]Button text[/su_button]
    Expands to: <a rel="noreferrer">
    Thread Starter Antal Tettinger

    (@antaltettinger)

    Thank you very much for the quick and helpful reply Vladimir!

    Thread Starter Antal Tettinger

    (@antaltettinger)

    Dear Vladimir,

    One thing please, I am trying to figure out with this filter but just can’t achieve it. I don’t want noopener, only nofollow (so rel=”nofollow”), but the button.php keeps prepending the noopener. Is there a way to deal with this please?

    Thanks,

    Antal

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Filter Button “noopener”’ is closed to new replies.