Shortcode not appearing when used as post content in wp_insert_post() or possibly, shortcode not being registered at all

You’re only registering the shortcode on activation. add_shortcode() is not persistent, and since shortcodes are parsed on output, the shortcode needs to be registered on every request. So you need to move add_shortcode() outside of the activation hook: function install_myplugin() { // … } function uninstall_myplugin() { // … } function myplugin_shortcode_reference() { // … … Read more

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

Weird failing request

Can you help me identify what the problem is and how can I prevent this? Where is this request coming from? The shortcode is only processed on the frontend. As far as the block editor is concerned the URL specified is [picsum] which is an unprocessed shortcode. There is no simple fix to this, and … 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

Unable to pull in custom product attribute in shortcode [closed]

In case anyone needs it, here was my final code: <?php //LIST ALL DOCUMENTS add_shortcode(‘listDocs’,’listDocs’); function listDocs(){ $params = array( ‘paged’ => get_query_var(‘paged’, 1), ‘posts_per_page’ => 25, ‘post_type’ => ‘product’, ‘product_cat’ => ‘documents’ ); $wc_query = new WP_Query($params); while ($wc_query->have_posts()) { $wc_query->the_post(); $product_id = get_the_ID(); $product = wc_get_product($product_id); $author = $product->get_attribute(‘written-by’); $date = get_the_date(‘F Y’, … Read more

Shortcode with ‘year’ parameter

With help from @bosco , I was able to figure it out. Below is the working code: //get archived posts per year add_shortcode( ‘archived-posts’, ‘archived_posts’ ); function archived_posts($atts) { $a = shortcode_atts( array( ‘year’ => date(‘Y’) ), $atts ); $q = new WP_Query(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1 , ‘post_status’ => ‘archive’ , ‘year’ … Read more

shortcode executed in the page editor

From the add_shortcode() docs: Note that the function called by the shortcode should never produce an output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results. Your code should be: function vbshort_shortcode() { return ‘Hello shotcode!’; } … Read more

Custom shortcode works in Elementor editor but not on frontend

The problem is with the require_once, you are passing a relative path and that path doesn’t exist. Assuming the test.php file you want to require is in this path wp-content/themes/your-theme/views/test.php You can use the following require_once locate_template(‘views/test.php’); Consider using include instead of require_one, if this shortcode is not 100% necessary for your site to function, … Read more