Run PHP Results inside WP Shortcode

If I understand correctly, you have a shortcode called wp_charts that accepts a pramaeter datasets, and you want to create a new shortcode that runs a database query and embeds the results of the query as the value of datasets? If so, there are several ways to do this, but I think the easiest – … Read more

WordPress plugin shortcodes not outputting anything

wp_remote_get doesn’t return a string, it returns an array, and if we refer to the documentation: $response = wp_remote_get( ‘http://www.example.com/index.html’ ); if( is_array($response) ) { $header = $response[‘headers’]; // array of http header lines $body = $response[‘body’]; // use the content } Here $response would not be a json string, but an array containing the … Read more

Use html tags in shortcode_atts, is it real?

While it is a technically possibility, it’s most likely direction that isn’t worth it. Overuse of shortcodes for what is essentially (crappy) templating is problematic and has a history of security issues. In recent months there has been ongoing planning and discussion about possibility of changes to shortocde syntax and mechanics in core. HTML in … Read more

PHP Shortcode – 500 error

Like @s_ha_dum said, those nightmarish “template tag” style conditionals made it hard to find those errors. Please use define( ‘WP_DEBUG’, true ); in your wp-config file to print those PHP errors while you are developing. function lande_galleri_parameter($atts) { extract( shortcode_atts( array ( ‘post_type’ => ’embm_beer’, ‘order’ =>’date’, ‘orderby’ => ‘title’, ‘posts’ => -1, ‘land’ => … Read more

php in a shortcode

First, get_footer() is meant to load page level template files, not post-level ones. You should be using get_template_part() instead. Shortcodes execute as a filter on the_content. Per the norms of all filters, they should return content, not echo it. echoing content will cause effects like you are seeing. Apparently, the template file you are loading … Read more

Retrieving Advanced Custom Field within Shortcode Function [closed]

“You have to explicitly pass post ID as the 2nd argument.” – Milo In the Advanced Custom Fields plugin file, plugins/advanced-custom-fields/core/api.php, get_fields has a default $post_id of false, and calls on get_field_objects, which seems to run specific calls to $wpdb->get_col($wpdb->prepare, depending on what $post_id contains (is_numeric?, strpos(‘user_’)), so I guess depending on the environment of … Read more

shortcode function outputs multiple anchor tags

You are trying to remove the filter before adding the filter and one more thing you are not adding the correct priority. remove_filter( ‘the_content’, ‘wpautop’ ); //removing before adding without priorities. add_filter( ‘the_content’, ‘wpautop’ , 99) ; add_filter( ‘the_content’, ‘shortcode_unautop’, 100 ); Try remove the filter at the end with same priority when you add. … Read more

Custom shortcode is not working inside tabs

As the article shows, ob_start and ob_get_clean can capture typical loop output and return as a variable. When you’re in the loop you might want to make sure the_content renders it’s shortcode as well. function do_livecasinoss_shortcode($atts, $content = “”) { // start the buffer ob_start(); $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args = array( … Read more