Shortcodes: closing shortcode not being processed

The reason echo do_shortcode(“[/expand]”); is not working is because [/expand] is not a valid shortcode on it’s own. The combination of [expand] and [/expand] is valid so echo do_shortcode(“[expand] some content [/expand]”); should work as intended. If you want to use this way of seting things up <?php echo do_shortcode(“[expand]”); ?> content <?php echo do_shortcode(“[/expand]”); … Read more

Adding a class to shortcode API

If it really is just for one page you could use a conditional on the_ID(); from within your shortcode class (it is a custom shortcode right?) $class = the_ID() == 213 ? “some-other-class” : “”; $myhtml = sprintf(“<div class=”some-class %1$s”>%2$s</div>”, $class, $content); The other option is to add parameters or “attributes” to your shortcode as … Read more

Favorite websites with shortened hyperlinks

Sure, you’re looking for the shortcode API. That would enable you to write a short piece of code that does exactly what you want. As easy as this in your functions.php: function wpse246274_wiki( $atts ) { $link = “http://en.wikipedia.org/wiki/” . $atts[‘link’]; return $link; } add_shortcode( ‘wikilink’, ‘wpse246274_wiki’ ); Which you would use like this in … Read more

Shortcode called twice

Shortcodes should never echo; they should always return the text to be displayed. See the User Contributed Notes in the add_shortcode() docs. Your code should read more like this: function displayTable() { $string = ”; $string .= ‘<table>’; $string .= ‘<tbody>’; $fields = get_field_objects(); foreach($fields as $field) { $string .= ‘<td>’; $string .= ‘<td>’. $field[‘label’] … Read more

Custom recent-posts shortcode’s thumbnail image not in line with rest of code

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’ => get_the_title()])

Shortcode attributes don’t appear?

You are return two times! The first return exit the function, so your shortcode outputs always “Hello World”. Correct code: function hello( $atts ) { extract( shortcode_atts( array( ‘foo’ => ‘something’, ‘bar’ => ‘something else’, ), $atts ) ); print_r($atts); // Remove, when you are fine with your atts! return ‘Hello, World: ‘.$atts[‘foo’]; } add_shortcode(‘hw’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)