shortcode_atts – one URL variable not working

First of all, you’re using extract / shortcode_atts in correctly: The line: extract(shortcode_atts(array( “li” => get_option(‘li’), ), $liatts)); uses shortcode_atts and then extracts turns each key in the returnarray into its own variable: e.g. $li in this example. But you then go onto use $liatts anyway – which is just the attributes passed from the … Read more

Storing Options in a Shortcode

If you want to alter display based on admin options, you don’t need to deal at all with the shortcode_atts ar the $attributes that are passed into your callback. The attributes passed in (and set by shortcode_atts) are meant to alter the way a shortcode works based on how an end-user uses it. Take this: … Read more

How to get gallery id inserted to a post?

In single.php i put this code, from this link (thank you Wyck) https://stackoverflow.com/questions/14277794/wordpress-3-5-own-gallery-with-included-images-doesnt-work preg_match(‘/\/’, $post_content, $ids); $array_id = explode(“,”, $ids[1]); print_r($array_id); Now I can use gallery shortcode

Shortcodes and a list of IDs?

explode will be your best option. WordPress has a few built in functions to handle arrays of function arguments (wp_parse_args and shortcode_atts for example), but nothing relating to splitting a string and iterating the result. It’s not entierly clear to me what you are trying to achieve, but let’s say you were trying to get … Read more

Add htmlentities and/or shortcode into data-attributes

the_field echoes the output while htmlentities() expects the value to be returned. Try get_field instead: data-img=”<?php echo htmlentities(get_field(‘portfolio_galleries’)); ?>” UPDATE: Instead of adding this huge chunk of html for the slider to the data-attribute just add it after your image: <img src=”https://wordpress.stackexchange.com/questions/93587/<?php echo $large_image ?>” data-title=”<?php echo get_the_title(); ?>” data-description=”<?php the_content();?>” alt=”<?php echo get_the_title(); // … Read more

Shortcode for a link and thumbnail

You are assigning the attachment URL to your $url variable: $url = wp_get_attachment_url( get_post_thumbnail_id( $id ) ); then passing that same variable back to wp_get_attachment_url: return ‘<img src=”‘ . wp_get_attachment_url( $url ) . ‘”/><a href=”‘ . get_permalink( $id ) . ‘”>’ . get_the_title( $id ) . ‘</a>’; You should simply output it instead: return ‘<img … Read more

detect when shortcode ran for the last time

Not sure about the last time, but you can hijack every shortcode and either call wp_localize_script() here or register an action for wp_footer that runs earlier than the footer script handler. Let’s say, this is the original: add_shortcode( ‘foo’, ‘original_function’ ); Now you can overwrite it with: add_shortcode( ‘foo’, ‘new_function’ ); function new_function( $atts, $content=””, … Read more