Shortcode outputs at the top of the_content

All functions have to return a string, you should not use echo anywhere. Rewrite the functions, use an internal variable to handle the strings and return that: // Output a single menu item function projects_menu_entry($id, $title, $link_self) { global $blog_id; $out=””; if ($link_self || $id != $blog_id) { $out .= ‘<li>’; if ($id == $blog_id) … Read more

How does a shortcode work?

When using the_content(), WordPress will run several filters to process the text coming from the editor. These filters process the content before it is sent to the browser. do_shortcode is the filter that handles shortcodes. From /wp-includes/default-filters.php: // Shortcodes add_filter( ‘the_content’, ‘do_shortcode’, 11 ); // AFTER wpautop() do_shortcode() is used to search content for shortcodes … Read more

Shortcode empty attribute

There could be a couple ways to do this. Unfortunately, I don’t think any will result in exactly what you’re going for. ( [paragraph last] ) You could just create separate shortcodes for [paragraph_first] [paragraph_last] [paragraph_foobar] that handle $content without needing any attributes You could set the default value for last to false instead of … Read more

Using get_option() in JavaScript

Define an array of parameters to be injected into the script: $script_params = array( ‘myWidth’ => get_option(‘my_width’) ); Localize the script via wp_localize_script: wp_localize_script( ‘your-script-handle’, ‘scriptParams’, $script_params ); scriptParams now is a js object you can access from within the script: alert( scriptParams.myWidth ); // the value from the PHP get_option call in the js

WordPress plugin shortcode not working

There are a couple of things to check here One: Is your plugin activated. Two: Is your shortcode in your main plugin file. If that code is in another file inside your plugin, did you make sure to include that extra file into your main plugin file Three: Don’t you have any type of error … Read more

shortcodes output before content [duplicate]

Shortcode callbacks have to return, not output. So use the following: function test() { return ‘-TEST-‘; } add_shortcode( ‘testshortcode’, ‘test’ ); More info: http://codex.wordpress.org/Shortcode_API If you have to use echo you can also do it this way(useful if there’s a lot of markup & it’s difficult working with strings)- function test() { ob_start(); echo ‘-TEST-‘; … Read more

Custom shortcode being executed when saving page in wp-admin

Shortcodes must return, not echo or print their output. As the Codex entry for add_shortcode() explains: Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results. … Read more

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