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?

Regards!

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>       rnd.today=new Date();     rnd.seed=rnd.today.getTime();      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("a.com", "b.com");     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?

How to pass parameters in wordpress shortcode?

Everything is working fine and it’s displaying the comments of the current page with this shortcode [wpdiscuz_comments] using the code below.

function my_wpdiscuz_shortcode() { $  html = ""; if (file_exists(ABSPATH . "wp-content/plugins/wpdiscuz/themes/default/comment-form.php")) { ob_start(); include_once ABSPATH . "wp-content/plugins/wpdiscuz/themes/default/comment-form.php"; $  html = ob_get_clean(); } return $  html; } add_shortcode("wpdiscuz_comments", "my_wpdiscuz_shortcode"); 

I’m trying to pass id parameter using the shortcode below. But it’s not working.

[wpdiscuz_comments post_id="22"] 

Where "post_id" parameter fetching the comments of only post id 22. So I can fetch the comments of a specific post.

Can anyone please help me with this or let me know how can I pass the parameters with shortcode using the above code? Thanks!

How do I hide the event description within template of The Events Calenar using Ultimate Member shortcode?

OK, so the goal is to hide the event description with Ultimate Member shortcode [um_loggedin].

I tried doing echo do_shortcode but it’s not working…

This is the code I used within wp-content/themes/hello-elementor/tribe-events/single-event.php:

<?php echo do_shortcode('[um_loggedout]'."Sorry, but only loggedin users are allowed to access the details".'[/um_loggedout]');?>

<?php echo do_shortcode('[um_loggedin]'.the_content().'[/um_loggedin]');?>

How to utilise multiple values from a single shortcode attribute?

i.e [test somevalues=1,2,3,4,5]

First time poster and alsoa php newb, I’m trying to add a feature to a plugin but I seem to keep triggering a debug notice from wordpress.

$  somearray = shortcode_atts([                'somevalues' => null,     ], $  atts); $  somearray['somevalues'] = array_map( 'trim', str_getcsv( $  somearray['somevalues'], ',' ) );  

The above does work, but it results in a debug Notice: wpdb::prepare was called incorrectly.

Is there a way to achieve the same without triggering the notice? It doesn’t have to be csv, I just need it to return a string of somevalues, rather than returning an int. I guess what I want it to act like is as if it was written like [test somevalues=one,two,three,four,five]

Any suggestions on how to get around this? Many thanks

Hot to generate shortcode with TinyMCE custom button in WP 5.x?

I’ve created custom shortcode for CTA button:

function cta_shortcode_function( $  atts ) {          $  a = shortcode_atts( array(         'url' => '#',         'text' => 'cta button',         'icon' => '<i class="far fa-caret-square-right"></i>',         'target' => '_blank',         'align' => 'center',      ), $  atts );      echo     '<div class="l-cta '.$  a['align'].'">         <a class="c-cta " href="'.$  a['url'].'" target="'.$  a['target'].'">';         if ( 'before' == get_theme_mod('cta_general_icon_position', true)) {             echo             '<span class="e-cta__icon e-cta__icon--before">                 '.$  a['icon'].'             </span>';         }         echo '<div class="e-cta__text">'.$  a['text'].'</div>';         if ( 'after' == get_theme_mod('cta_general_icon_position')) {             echo              '<span class="e-cta__icon e-cta__icon--after">                 '.$  a['icon'].'             </span>';         }         echo         '</a>     </div>'; }  add_shortcode('cta_shortcode', 'cta_shortcode_function'); 

Now I would like to create this shortcode via button in TinyMCE Editor, so what I did is:

/* Custom button in TinyMCE editor */ function mce_cta_button() {     if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {         add_filter( 'mce_external_plugins', 'custom_tinymce_plugin' );         add_filter( 'mce_buttons', 'register_mce_buttons' );     } } add_action('admin_head', 'mce_cta_button');   // Path to the js file with the custom button function function custom_tinymce_plugin( $  plugin_array ) {     $  plugin_array['mce_cta_button'] = get_template_directory_uri() .'/js/tinymce_buttons_cta.js';     return $  plugin_array; }  // New button in the editor function register_mce_buttons( $  buttons ) {     array_push( $  buttons, 'mce_cta_button' );     return $  buttons; } 

and ofc the JS file:

(function () {   tinymce.PluginManager.add('mce_cta_button', function(editor, url) {       editor.addButton('mce_cta_button', {           icon: false,           text: 'CTA button',           onclick: function (e) {               editor.windowManager.open( {                   title: "CTA button's things",                   body: [{                       type: 'textbox',                       name: 'Icon from FontAwesome',                       placeholder: 'Copy and paste <i> object from FontAwesome site',                       multiline: true,                       minWidth: 420,                   },                   {                     type: 'listbox',                     name: 'align',                     label: 'CTA align',                     maxWidth: 420,                     values: [                         {                             text: 'Start',                             value: 'start'                         },                         {                             text: 'Cenetr',                             value: 'center'                         },                         {                             text: 'End',                             value: 'end'                         }                     ]},                   {                       type: 'button',                       name: 'link',                       text: 'Insert/Edit link',                       onclick: function( e ) {                           //get the Wordpess' "Insert/edit link" popup window.                           var textareaId = jQuery('.mce-custom-textarea').attr('id');                           wpActiveEditor = true; //we need to override this var as the link dialogue is expecting an actual wp_editor instance                           wpLink.open( textareaId ); //open the link popup                           return false;                       },                   }],                   onsubmit: function( e ) {                       editor.insertContent( 'MY SHORTCODE');                   }               });           }       });   }); })(); 

What I don’t know is how to connect my shortcode to this button and why link window doesn’t work correctly (buttons "ok" or "cancel" aren’t working, I can’t close this window and can’t search pages).

Any help?

Thanks

Display page and custom post title inside shortcode

I trying to write shortcode to display page title but only got the archive title to work but not custom post type category and single post. Can anyone shed light how to do this? Reason for going this path is Elemenentor theme builder generate too much code for simple page title and subheading inside secondary header that is masked wrap around image. I use the shortcode widget to insert the code and style it.

So far this is what I have written:

// Page Title inside shortcode function page_title_sc( ) {     $  title = ('Page Title');     if ( is_post_type_archive() ) {     $  title = post_type_archive_title( '', false );   }   elseif ( is_page() ) {     $  title = single_post_title();    }     return apply_filters( 'page_title_sc', $  title ); }   add_shortcode( 'page_title', 'page_title_sc' ); 

Shortcodes — Using add_action, add_filter in the shortcode

A client wants the following:

  • User clicks on a specific button which takes them to a partner’s site.
  • If this is their first time clicking the link, they need to accept terms and conditions.
  • If they’ve already accepted, button takes them directly to link.
  • The client insists on being able to update everything (URL, button text) themselves, so I’m can’t hard code those values into the function.

In order to pull this off, I wrote a shortcode with attributes, and I’m using Gravity Forms hooks (gform_after_submission and gform_confirmation). I want these hooks to reference the shortcode attributes.

So if we use: [big_data_EULA url="http://www.example.com"] then gform_confirmation can use $ url.

— —

I’ve tried two, things:

  1. Including the add_action and add_filter within the shortcode function
  2. Passing the variables from the shortcode to those hooks.

Could anyone help me figure out the right way to get this working?

Here’s my code:

 function big_data_EULA_function($  atts){    extract(shortcode_atts(array(       'url' => 'http://www.google.com',       'confirm_text' => 'ACA Big Data Resource',       'click_thru_text' => 'ACA Big Data Resource',       'form' => '22',     ), $  atts));         /// Some of these variables aren't used in this iteration but I would like to use in final form.        $  EULA_url = $  url;        $  EULA_confirm_text = $  confirm_text;        $  EULA_click_thru_text = $  click_thru_text;        $  EULA_gravity_form = $  form;        $  EULA_user_ID = get_current_user_id();        $  EULA_meta_key = "_bigdata_EULA";        $  check_meta = get_user_meta( $  EULA_user_ID, $  EULA_meta_key, true );         if ($  check_meta) {           $  button ='<div class="box-button white-button optimize-button"><a href="' . $  EULA_url . '">' . $  click_thru_text . '</a></div>';          return $  button;         } else {           ob_start(); // start a buffer            echo '<div style="display: none; max-width: 60%;" id="hidden-content">';            echo gravity_form( 22, false, false, false, '', true );            echo '</div><div class="box-button white-button optimize-button"><a data-fancybox data-src="#hidden-content" href="javascript:;">' . $  EULA_confirm_text . '</a></div>';          $  output_string = ob_get_contents();          ob_end_clean();          return $  output_string;       };   };  // Update the user_meta flag only if they've actually accepted the EULA, ie, submitted the form. add_action( 'gform_after_submission_22', 'bigdata_EULA',10, 1 );   function bigdata_EULA() {     $  EULA_user_ID = get_current_user_id();     $  EULA_meta_key = "_bigdata_EULA";     $  current_date = date("F j, Y");      update_user_meta( $  EULA_user_ID, $  EULA_meta_key, $  current_date);   };   // Redirect to the partner site. The redirect URL should come from the shortcode. add_filter( 'gform_confirmation_22', 'custom_confirmation', 10,1 );   function custom_confirmation( $  confirmation) {     $  EULA_url = 'http://www.google.com';      $  confirmation = array( 'redirect' => $  EULA_url );   return $  confirmation; }   add_shortcode('big_data_EULA', 'big_data_EULA_function');