Shortcode for Comments and Comment Boxes in Post Loop

Is it possible to get the comments and comment boxes for each post in a loop so users do not have to navigate to the actual single post page to leave a comment (and instead users can leave comments on the page where the loop is placed)?

I am trying to create a shortcode for the comment boxes to be placed inside a loop but the below shortcode only calls the comment box for the current page or single page as per WordPress Developer guide.


function show_comments_shortcode() {      global $  withcomments;   $  withcomments = true;      // This only gets the current single or page comment  $  showcomments = comments_template( '', true );    // Return Comments for each post in loop return $  showcomments; }  // register comments shortcode add_shortcode('show_comments', 'show_comments_shortcode');  

Thank you for any feedback in advance.

Shortcode letting user to “join” the multiple user roles

It is possible to create some sort of shortcode which allows users to "join" the particular user role from frontend? Like if user is subscriber by default to let him join also user role such as "supporter" so he will be subscriber but also supporter?

And the second one the opposite – to let users from frontend "leave" the particular user role if they are members of it.

I’ve tried to google it, but I found only code to let users to switch between roles and I can’t figure out how to make it to let users to be member of multiple roles.

P. S. I am using plugin which allows me to have multiple user roles, so I am not limited by default WP functionality in this.

Associate custom field with custom taxonomy with shortcode in backend

I am trying to associate a custom field to a custom taxonomy booked_custom_calendar. Custom field here is [notifications_user_id]. All this will be executed using a shortcode. When user clicks on Generate Calendar button, a term will be created and assigned to the current user using custom field and current user’s email as value in it. In this way I can filter and show this term (booked_custom_calendar) anywhere by comparing the email of current user and value in custom field.

Please help me save this field to custom taxonomy.

function createMyCustomCalendar(){      $  current_user = wp_get_current_user();     $  custom_calendar_name = "$  current_user->display_name\'s - Calendar";          $  parent_term = term_exists( $  custom_calendar_name, 'booked_custom_calendars' ); // returns an array if the taxonomy exists     $  parent_term_id = $  parent_term['term_id']; // get the numerical value of the term          $  insert_data = wp_insert_term(     $  custom_calendar_name, // new term     'booked_custom_calendars', // taxonomy     array(     'description' => $  current_user->ID,     'slug' => '',     'parent' => $  parent_term_id     )     );     //Add new meta field and fill with user ID |     // add_term_meta($  term_id, 'term_author_id', $  current_user->ID, true);          if( ! is_wp_error($  insert_data) )     $  term_id = $  insert_data['term_id'];   // A callback function to add a custom field to our "presenters" taxonomy      // Check for existing taxonomy meta for the term you're editing       $  t_id = $  term_id; // Get the ID of the term you're editing       $  term_meta = get_option( "taxonomy_term_$  t_id" ); // Do the check   ?>      <tr class="form-field">        <td>           <input type="text" name="term_meta[notifications_user_id]" id="term_meta[notifications_user_id]" size="25" style="width:60%;" value="<?php echo $  current_user->data->user_email;?>"><br />       </td>   </tr>     <?php           //$  t_id = $  term_id;           //$  term_meta = get_option( "taxonomy_term_$  t_id" );           $  cat_keys = array_keys( $  _POST['term_meta'] );               foreach ( $  cat_keys as $  key ){                   $  term_meta[$  key] = $  _POST['term_meta'][$  key];                                    //save the option array           update_option( "taxonomy_term_$  t_id", $  term_meta );               }     echo '<script>window.location.replace("'.get_admin_url().'?page=booked-appointments");</script>';      }     function showCustomCalendarButton(){  ?>     <form method="post"> <input type="submit" name="button1"  id="btn-1" value="Generate Calendar"/></form>  <?php if(isset($  _POST['button1'])) { createMyCustomCalendar(); }  }  add_shortcode('create-custom-calendar','showCustomCalendarButton'); ?> <?php 

Shortcode don’t work ? An idea?

I want to create a shortcode where content is displayed if user meta is equal to a value

But i want multiple values possible

show content if usermeta firstname is cory or jeff or boris…

Exemple [usermeta_value usermeta="firstname" uservalue="Cory,Jeff,Boris"] show content [/usermeta_value]

function func_usermeta_value( $  atts, $  content = null ) if ( is_user_logged_in() ) {  $  user_meta = $  atts['usermeta'];     $  user_value = $  atts['uservalue']; $  allowed_value = explode(',', $  user_value);          $  user_id = get_current_user_id();      $  user_data = get_userdata( $  user_id );      if ( strtolower($  user_data->$  user_meta) == strtolower($  allowed_value) ) {          return do_shortcode($  content); /* show content from shortcode */     } } return ''; } add_shortcode( 'usermeta_value', 'func_usermeta_value' ); 

Thx for your help

Shortcode not work in picture source srcset tag

i have in my WP plugin:

<picture>     <source srcset="[bloginfo key='template_url']/images/image.webp" type="image/webp">     <img src="[bloginfo key='template_url']/images/image.png"> </picture> 

In a browser, img src code is OK, but on a srcset stays [bloginfo key=’template_url’]. What i missing about shortcode and srcset attribute to display it right?


Shortcode to update user meta

I want to create a button on the front end and when user click, the value "user-meta" change ‘validate’

function func_change_validate() {     if (is_user_logged_in()) {         $  current_user = wp_get_current_user();           $  new_value = 'validate';         $  updated = update_user_meta( $  user_id, 'User_meta_change', $  new_value );                     return 'here i want create bootom to updated ?? <button type="submit">Validate</button>';     } }  add_shortcode('change_validate','func_change_validate'); 

Convert HTML Script to Shortcode

I want to convert this code into a shortcode from the Code Snippets plugin, I have seen an example come up but when I put it it does not work, the example is the following:

add_shortcode( 'shortcode_name', function () {      $  out = '<p>write your HTML shortcode content here</p>';      return $  out; } ); 

I want to convert the following code to rotate banners:

<script> Date();;      function rnd() {         rnd.seed = (rnd.seed*9301+49297) % 233280;         return rnd.seed/(233280.0);     }      function rand(number) {         var result = Math.floor(rnd() * number);         if (!result) result = 0;         return result     }     var bannerimgs = new Array("a.jpg", "b.jpg");     var bannerlnks = new Array("", "");     var banneralt = new Array("a", "b");     var rotatorHtml = "";     var endJs = "";      for(var img in bannerimgs){         var thisImg = new Image();         thisImg.src = bannerimgs[img];     }     var bannerimgCt = 2;     var bannercurrentAd = rand(bannerimgCt);     var openlink = "";     var bannerbanner = document.getElementById('banner');     var bannerlink = document.getElementById('banneradLink');              if(bannerlnks[bannercurrentAd] != ""){         rotatorHtml += '<a href="' + bannerlnks[bannercurrentAd] + '" id="banneradLink"  target="_blank">';         endJs = "</a>";     }     rotatorHtml += '<img src="' + bannerimgs[bannercurrentAd] + '" alt = "' + banneralt[bannercurrentAd] + '" id="bannerbanner">' + endJs;     document.getElementById("banner_div").innerHTML = rotatorHtml;   </script> 

How can this script be converted to a shortcode? I have replaced what it says but errors appear, then I do something wrong. How can this script be converted to a shortcode? Do you know any other way?