custom field value as shortcode parameter

I never worked with this plugin, just downloaded it from repository and found that they provide a filter for id value. Add this filter callback function to your functions.php file. [download id=”auto”] – will use id from your post meta (hardcoded meta name) [download id=”123″] – will use id 123 function download_shortcode_custom_id($id, $atts = []){ … Read more

Change user meta value with shortcode

You made error, you made checks on the value which were null, i compile your code and made changes, here is the code it will help you. function wp_change_namecar( $atts, $content = null ) { if (is_user_logged_in()) { $user_id = get_current_user_id(); $userval =$_POST[‘cars’]; //how to define that it is the value of the form? if … Read more

Shortcode argument multiple values

It depends on the plugin. WordPress does not natively support passing multiple values to a shortcode attribute. The value you’re passing to the shortcode is simply ‘1,2’. How that value is handled depends entirely on how the shortcode was implemented by the developer.

How do I define and register a shortcode function in a namespaced functions.php file?

Thanks to Stanislav Khromov (also active on WPSE!), I learned any Callable referenced in add_shortcode() must be fully qualified, even if it is defined in the same file you’re referencing it. <?php /** * theme’s functions.php */ namespace MyNamespace; //[foobar] function foobar_func( $atts ){ return “foo and bar”; } add_shortcode( ‘foobar’, ‘\MyNamespace\foobar_func’ ); You may … Read more

When are Shortcode Attributes Available in Template

I need access to the shortcode attributes before the content (and it’s shortcode) is processed…. in the first “is $atts available here” after the add_shortcode In that case, you can manually parse the shortcode and retrieve its attributes (if any) like so, which uses get_shortcode_regex() and shortcode_parse_atts(): $content=”before blah2 [foo bar=”baz” num=”123″] after”; preg_match( “https://wordpress.stackexchange.com/” … Read more

Adding custom form within add_shortcode

whenever I paste the shortcode in the page editor the form posts automatically and redirects to /wp-admin/admin-post.php with a blank screen I don’t know what editor is that (🤔), and I’m not sure if this will fix the above issue, but I noticed your function is using wp_nonce_field() which by default displays/echo the output, so … Read more

How to create a shortcode to let the user add the ID of a YouTube video?

add_shortcode(‘youtube’, ‘youtube_shortcode’); function youtube_shortcode($atts){ if(!isset($atts[0])) return; $id = strip_tags($atts[0]); ob_start(); ?> <div><a class=”fancybox” href=”#video_<?php echo $id; ?>”> <img src=”http://img.youtube.com/vi/<?php echo $id; ?>/0.jpg” alt=”Welcome To High Output” width=”220px” height=”120px” /></a></div> <div id=”video_<?php echo $id; ?>” style=”display: none;”> <iframe title=”YouTube video player” class=”youtube-player” type=”text/html” width=”480″ height=”390″ src=”http://www.youtube.com/embed/<?php echo $id; ?>” frameborder=”0″ allowFullScreen></iframe></div> <?php return ob_get_clean(); } use … Read more