Display Data in Table from External Database in WP using Shortcodes

While it is VERY bad practice to have spaces in the object names, there are times where it may be out of your control. You can use the syntax of $object->{‘Property Name’}, like this: // add the shortcode [pontoon-table], tell WP which function to call add_shortcode( ‘pontoon-table’, ‘pontoon_table_shortcode’ ); // this function generates the shortcode … Read more

How to dynamically add wordpress shortcodes

Assuming the $row->internalFunction is a function, or the name of a function which already exists, then you can do something like so: foreach ( $dbQuery as $row ) { add_shortcode( $row->formName, $row->internalFunction ); } So if the formName (shortcode tag) is foo and internalFunction is foo_func, then [foo] will be handled by the foo_func() function: … Read more

Shortcode from a function not working

If you refer to the documentation for add_shortcode, you need your function to return the content: function uniquetestfunction($attributes) { return ‘<div class=”my_class”>Test Element</div>’; } add_shortcode(‘uniqueshortcodename’,’uniquetestfunction’); You also used the wrong quotes in your add_shortcode line – stick with single ‘ or double ” quotes.

Add shortcode with open close function

To change the functionality of a shortcode you must first remove_shortcode( ‘shortcode_name’ ); where shortcode name is the name of the shortcode. Add the shortcode back with your NEW function. A simple example to follow what you might be needing: remove_shortcode( ‘mybutton’ ); add_shortcode( ‘mybutton’, ‘my_shortcode_function’ ); my_shortcode_function( $atts, $content = “” ) { return … Read more

Gutenberg Shortcode Fail

The shortcode doesn’t work because it’s wrapped inside quotes — “[current_user]”. But a better explanation is, because it’s in a HTML attribute. And it’s not a Gutenberg or the block editor problem; even with <?php echo do_shortcode( ‘<input name=”name” value=”[current_user]” type=”hidden”>’ ); ?>, the shortcode would still remain as-is. Because shortcodes in HTML attributes are … Read more

List taxonomy term slugs within shortcode (do_shortcode)

The do_shortcode() function is currently in the foreach loop. I don’t know what are the parameters of this shortcode , but if it accepts comma separated values of term slugs: $terms = get_the_terms( $post->ID , ‘shoptype’ ); $i=1; $commaSeparatedvalues=””; foreach ( $terms as $term ) { $term_link = get_term_link( $term, ‘shoptype’ ); if( is_wp_error( $term_link … Read more

When echoing my own shortcode, it keeps adding a 1 at the end of my blogpost

This is your problem: public function listLayout() { return require( $this->plugin_path . “/admin/itemList.php” ); } Shortcodes need to return their output as a string, but this does not. The shortcode is outputting directly, rather than being output at the correct time by WordPress. This would become very apparent if nested shortcodes were used as the … Read more