Shortcode adding p and br tags

Not sure if this will be helpful to anyone else but the cause of the issue was a custom formatter the theme had: function my_formatter($content) { $new_content=””; $pattern_full=”{(\[raw\].*?\[/raw\])}is”; $pattern_contents=”{\[raw\](.*?)\[/raw\]}is”; $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($pieces as $piece) { if (preg_match($pattern_contents, $piece, $matches)) { $new_content .= $matches[1]; } else { $new_content .= wptexturize(wpautop($piece)); } … Read more

Allowing shortcodes inside attributes

Sorry, brackets are still not allowed within shortcodes, as you can see in the Shortcode API. However it’s possible to use enclosing shortcodes which will allow to use brackets. Let me demonstrate this: Shortcode: [foo bar=”No brackets here!”]…use [brackets] here[/foo] You can add this kind of shortcode in your functions.php like this: add_shortcode( ‘foo’, ‘foo_shortcode’ … Read more

How to prevent newline from appearing in shortcode?

The <br> tag is coming from wpautop(), which is one of a number of display filters added to the content via wp-includes/default-filters.php: // Display filters add_filter( ‘the_content’, ‘wptexturize’ ); add_filter( ‘the_content’, ‘convert_smilies’, 20 ); add_filter( ‘the_content’, ‘wpautop’ ); add_filter( ‘the_content’, ‘shortcode_unautop’ ); add_filter( ‘the_content’, ‘prepend_attachment’ ); add_filter( ‘the_content’, ‘wp_make_content_images_responsive’ ); … // Shortcodes add_filter( ‘the_content’, … Read more

Add custom shortcode button to Editor

I found it, WordPress made changes and you can now add buttons through a simple API if( !function_exists(‘_add_my_quicktags’) ){ function _add_my_quicktags() { ?> <script type=”text/javascript”> /* Add custom Quicktag buttons to the editor WordPress ver. 3.3 and above only * * Params for this are: * string id Required. Button HTML ID * string display … Read more

TED talks shortcode not working

Unfortunately, this is going to be a problem for you. The [ted] shortcode is specific to WordPress.com – not to a self-hosted site where you installed the software yourself from WordPress.org. The only embeds that WordPress.org’s software supports by default are listed in the Codex: YouTube (only public videos and playlists – “unlisted” and “private” … Read more

Display custom post type with shortcode

I think, basically your question is, how to query posts of a custom post type in a shortcode. You should have a look into the WP_Query section of WordPress: https://codex.wordpress.org/Class_Reference/WP_Query In my example code I create a shortcode, which shows the title of the latest published posts of the type ‘my-custom-post-type’: <?php add_shortcode( ‘shortcodename’, ‘display_custom_post_type’ … Read more

Table of Contents with a shortcode

The easiest way would be to replace $content = $toc . $content; with $content = str_replace( ‘[toc]’, $toc, $content ); This would do a search for the string [toc] and replace it with the table of contents. It might be more complicated due to how the plugin would work, but on paper it is simple.

Autoembeds don’t work with paragraphs

The reason why this is happening, seems to be found in the file wp-includes/class-wp-embed.php in the autoembed call-back method: /** * Passes any unlinked URLs that are on their own line to {@link WP_Embed::shortcode()} for potential embedding. * * @uses WP_Embed::autoembed_callback() * * @param string $content The content to be searched. * @return string Potentially … Read more

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