New answers tagged

0

Thanks everybody for your help, it helped me go in the correct direction. Here is my final code: function mmx_recent_posts_shortcode() { $args = array( 'orderby' => 'date', 'posts_per_page' => 3 ); $posts = get_posts( array( $args ) ); foreach ( $posts as $post ) { if ( has_post_thumbnail( $post->ID ) ) { ...


0

Lots of possible causes obviously - DNS, routing, firewall, an issue with their server or app, or an issue with your server or app. One possible issue on their end that you could easily identify - if they're using round-robin DNS queries for the api hostname, maybe one of the api endpoints is broken and your request fails when it hits that endpoint. This ...


2

The problem is: the_post_thumbnail() outputs its content immediately. It's basically like echoing instead of returning. To fix it, you should be able to just replace the_post_thumbnail('thumbnail', ['class' => 'droplet-img', 'title' => get_the_title()]) with get_the_post_thumbnail('thumbnail', ['class' => 'droplet-img', 'title' => ...


0

As per the documentation it's not possible without either amending the shortcode or making your own (which is the better option) using add_shortcode


0

If you would rather want to get the sorting menu using a shortcode then you can create one for it in your functions.php // Creating Shortcode for Product Sorting add_shortcode('wc_sorting','woocommerce_catalog_ordering'); Then simply call the shortcode in your catalog page:- In Legacy Editor/Gutenberg: [wc_sorting] or in your PHP file: echo do_shortcode('[...


3

It's because if the user enters large="true", then $atts['small'] isn't defined. The normal solution is to use shortcode_atts() to set default values for the parameters, but you're not putting the result of shortcode_atts() into $atts, you're just just extracting it. This means that $small will be defined, but $atts['small'] won't be. The proper way to ...


1

Try this: function banner_shortcode() { $banner = esc_url( get_stylesheet_directory_uri() . '/images/banner.jpg' ); $banner__feature = esc_url( get_stylesheet_directory_uri() . '/images/banner__feature--easter.jpg' ); return '<div class="banner banner--call-now" data-parallax="scroll" data-bleed="100" data-image-src="' . $banner . '"> ...


0

Use directly in the templates. echo strip_shortcodes( get_the_excerpt() ); how does it work as follows ? add_filter('the_excerpt', 'strip_shortcodes'); or add_filter('get_the_excerpt', 'strip_shortcodes');


0

I think your "do_shortcode" is not parsing the variable. Try with this code: echo do_shortcode('[datatable id=30 var1="'.$idnr.'"]'); * Note the ' before and after the .


0

It's an OK practice but in some cases could be turned to a worst case scenario! Using shortcodes to generate blocks of HTML is the reason they exist, especially when you need some dynamic HTML generation (using attributes in the shortcode). In conclusion, a normal shortcode usage is totally OK, however you should avoid putting hundreds of shortcodes in ...


0

I know this is old but here is my answer and it can help anybody who's having similar challenge as mine. Based on @fuxia code, her code works perfectly but will only display one output. Assuming you have multiple instances of the shortcode on a page, Only one action hook will be added to footer. If you want to add multiple action based on the number of ...


0

Yes, you can keep nesting shortcodes. Just keep using the do_shortcode() until the deepest level is reached. https://codex.wordpress.org/Shortcode_API#Nested_Shortcodes So you can do this, [container] [other_column class="extra-class"] [content] col 1 [/content] [another] col 1-2 [/another] [/other_column] [column] [...


0

the error is saying to change ; to . - you will also want to remove the extra .: <?php echo do_shortcode("[svg-flag flag=\"" . get_post_meta($post->ID, 'ozellikler_text', true) . "\"]"); ?>


0

There's nothing to "generate". All Elementor is doing is giving an example of how to use their shortcode for a specific item. You only need one shortcode client, that accepts a parameter to determine which client to show: add_shortcode( 'client', function( $atts ) { $atts = shortcode_atts( [ 'id' => null ], $atts, 'client' ); if (...


0

You haven't defined $atts, so your function isn't receiving any of the attributes passed by the user. This isn't sufficient: $atts = shortcode_atts($defaults, $atts); That just combines $atts and $defaults into $atts, but the original $atts hasn't been defined. You need to accept $atts as the first argument passed to your function: function ...


Top 50 recent answers are included