Skip to main content
added 109 characters in body
Source Link
Rarst
  • 100k
  • 10
  • 161
  • 298
  1. First outside your shortcode callback function just register the stylsheet and then in shortcode callback function enqueue it. like:-

    function wpsoe_191512_avatar_shortcode_wp_enqueue_scripts() { wp_register_style( 'get-avatar-style', plugins_url( '/css/style.css' , FILE ), array(), '1.0.0', all ); }

add_action( 'wp_enqueue_scripts', 'brw_avatar_shortcode_wp_enqueue_scripts' );

if ( function_exists( 'get_avatar' ) ) {

First outside your shortcode callback function wpse_165754_user_avatar_shortcode ( $attributes ) { global $current_user; get_currentuserinfo(); extract(shortcode_atts(array( "id" => $current_userjust register the stylsheet and then in shortcode callback function enqueue it. like:->ID, "size" => 32, "default" => 'mystery', "alt" => '', "class" => '', ), $attributes, 'get_avatar' )); $get_avatar= get_avatar( $id, $size, $default, $alt );

    function wpsoe_191512_avatar_shortcode_wp_enqueue_scripts() {
  wp_register_style( 'get-avatar-style', plugins_url( '/css/style.css' , __FILE__ ), array(), '1.0.0', all );
  }


  add_action( 'wp_enqueue_scripts', 'brw_avatar_shortcode_wp_enqueue_scripts' );

  if ( function_exists( 'get_avatar' ) ) {

  function wpse_165754_user_avatar_shortcode ( $attributes ) {
            global $current_user;
            get_currentuserinfo();
            extract(shortcode_atts(array(
             "id" => $current_user->ID,
             "size" => 32,
             "default" => 'mystery',
             "alt" => '',
             "class" => '',
      ), 
      $attributes, 'get_avatar' ));
      $get_avatar= get_avatar( $id, $size, $default, $alt );

      wp_enqueue_style( 'get-avatar-style' );

      return '<span class="get_avatar '.$class.'">'.$get_avatar.'</span>';
      }
      add_shortcode ('get_avatar', 'wpse_165754_user_avatar_shortcode');
      }

Above is the example. You can use yours. Thanks

  1. First outside your shortcode callback function just register the stylsheet and then in shortcode callback function enqueue it. like:-

    function wpsoe_191512_avatar_shortcode_wp_enqueue_scripts() { wp_register_style( 'get-avatar-style', plugins_url( '/css/style.css' , FILE ), array(), '1.0.0', all ); }

add_action( 'wp_enqueue_scripts', 'brw_avatar_shortcode_wp_enqueue_scripts' );

if ( function_exists( 'get_avatar' ) ) {

function wpse_165754_user_avatar_shortcode ( $attributes ) { global $current_user; get_currentuserinfo(); extract(shortcode_atts(array( "id" => $current_user->ID, "size" => 32, "default" => 'mystery', "alt" => '', "class" => '', ), $attributes, 'get_avatar' )); $get_avatar= get_avatar( $id, $size, $default, $alt );

  wp_enqueue_style( 'get-avatar-style' );

  return '<span class="get_avatar '.$class.'">'.$get_avatar.'</span>';
  }
  add_shortcode ('get_avatar', 'wpse_165754_user_avatar_shortcode');
  }

Above is the example. You can use yours. Thanks

First outside your shortcode callback function just register the stylsheet and then in shortcode callback function enqueue it. like:-

    function wpsoe_191512_avatar_shortcode_wp_enqueue_scripts() {
  wp_register_style( 'get-avatar-style', plugins_url( '/css/style.css' , __FILE__ ), array(), '1.0.0', all );
  }


  add_action( 'wp_enqueue_scripts', 'brw_avatar_shortcode_wp_enqueue_scripts' );

  if ( function_exists( 'get_avatar' ) ) {

  function wpse_165754_user_avatar_shortcode ( $attributes ) {
            global $current_user;
            get_currentuserinfo();
            extract(shortcode_atts(array(
             "id" => $current_user->ID,
             "size" => 32,
             "default" => 'mystery',
             "alt" => '',
             "class" => '',
      ), 
      $attributes, 'get_avatar' ));
      $get_avatar= get_avatar( $id, $size, $default, $alt );

      wp_enqueue_style( 'get-avatar-style' );

      return '<span class="get_avatar '.$class.'">'.$get_avatar.'</span>';
      }
      add_shortcode ('get_avatar', 'wpse_165754_user_avatar_shortcode');
      }

Above is the example. You can use yours. Thanks

Source Link
dev
  • 301
  • 1
  • 7

  1. First outside your shortcode callback function just register the stylsheet and then in shortcode callback function enqueue it. like:-

    function wpsoe_191512_avatar_shortcode_wp_enqueue_scripts() { wp_register_style( 'get-avatar-style', plugins_url( '/css/style.css' , FILE ), array(), '1.0.0', all ); }

add_action( 'wp_enqueue_scripts', 'brw_avatar_shortcode_wp_enqueue_scripts' );

if ( function_exists( 'get_avatar' ) ) {

function wpse_165754_user_avatar_shortcode ( $attributes ) { global $current_user; get_currentuserinfo(); extract(shortcode_atts(array( "id" => $current_user->ID, "size" => 32, "default" => 'mystery', "alt" => '', "class" => '', ), $attributes, 'get_avatar' )); $get_avatar= get_avatar( $id, $size, $default, $alt );

  wp_enqueue_style( 'get-avatar-style' );

  return '<span class="get_avatar '.$class.'">'.$get_avatar.'</span>';
  }
  add_shortcode ('get_avatar', 'wpse_165754_user_avatar_shortcode');
  }

Above is the example. You can use yours. Thanks