the_excerpt and shortcodes
Paste this in your theme’s functions.php file add_filter( ‘the_excerpt’, ‘shortcode_unautop’); add_filter( ‘the_excerpt’, ‘do_shortcode’);
Paste this in your theme’s functions.php file add_filter( ‘the_excerpt’, ‘shortcode_unautop’); add_filter( ‘the_excerpt’, ‘do_shortcode’);
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
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
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
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
2 questions so 2 answers 🙂 Why is the current functions.php not working and adding styles to all pages? I’m not sure if it’s the global call or the if statement… It doesn’t work because of the order in which these functions are called. Your shortcode callback is called during rendering post content (most probably … Read more
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
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
This is untested, but the callback function is provided with an array of arguments, $args which give (if any) the paramters provided with the shortocode. The zeroth entry sometimes contains the name of the shortcode used (e.g. public_email). By sometimes I mean… The zeroeth entry of the attributes array ($atts[0]) will contain the string that … Read more
You can add a custom plugin, to WordPress and also the TinyMCE visual editor. The follow source is a example that simple works and add a string before and after all shortcode. Usage The shortcode will find via regex, relevant if you need it for different shortcodes and different mark on this. The script add … Read more