how to create shortcode in wordpress

You can create your short code just few steps. function short_codeFunction_name( $atts, $content=null ) { shortcode_atts( array(), $atts); $rowin = ‘<div class=”row”>’.do_shortcode( $content ) .'</div>’; return $rowin; } add_shortcode( “your_shortcode_name”, “short_codeFunction_name” ); Then you can access [your_shortcode]Here your content[your_shortcode] format inside the Post,page etc. add this function inside function.php in active theme directory. use inside … Read more

Using shortcodes in PHP

Referering to the Shortcodes API you can do echo do_shortcode(‘[helloworld]’); if your shortcode not in post. Or you can do echo apply_filters(‘the_content’, ‘[helloworld]’); but this will also bring other filters to work on your shorcode return html.

How to render complicated shortcodes

Good to hear that you managed to solve the problem already. Here’s a few examples on how you could also return html from a shortcode. As you already found out, you can use ob_start() and ob_get_clean() to buffer the html. Inside it you can echo the markup or drop out of PHP and write plain … Read more

Custom shortcode in widget forced to top of widget

For shortcodes you have to return the output for it to be written out where the shortcode appears. Either turn your HTML into a PHP string rather than breaking out of the PHP tags or you can use PHPs output buffering methods like so: ob_start(); ?> <div id=”player_<?php echo $id; ?>” class=”video_player”><a href=”http://www.adobe.com/products/flashplayer/”>Get the Flash … Read more

Shortcode created to check language not works

In a shortcode you always need to return something. It’s also good practice to make your code very logical and readable. Here are a list of PHP Logical Operators: http://php.net/manual/en/language.operators.logical.php Complete List of WordPress Locale Codes: https://wpastra.com/docs/complete-list-wordpress-locale-codes/ Below an example as English as a backup/fallback language: function coupon_shortcode() { $logged_in = is_user_logged_in(); if (get_locale() == … Read more

Automatically added brs and paragraphs?

You can postpone the wp_autop filter. WordPress has this filter enabled by default. And it is processing before the shortcode output. remove_filter( ‘the_content’, ‘wpautop’ ); add_filter( ‘the_content’, ‘wpautop’ , 12); Add this to your functions.php and check if the problem persist! See a similar problem here: stray <p> elements

How to display a shortcode caption somewhere other than the_content

Try this: $caption_info = array(); add_filter( ‘img_caption_shortcode’, ‘capture_caption’, 10, 3 ); function capture_caption( $blank = ”, $attr, $content ) { global $caption_info; $caption_info[] = array(‘attr’ => $attr, ‘content’ => $content ); return ‘ ‘; } It will save info from all captions into global $caption_info variable and suppress their display in content (space is returned … Read more

shortcode to create dynamic dropdown box form shortcode attributes

Based on your example at the bottom of your question, and your statement that you would like something like that for readability, I’d do something like this: function dropdown_option($atts) { $dropid = (isset($atts[‘dropid’])) ? $atts[‘dropid’] : ”; global $sco_array; if (!empty($atts[‘value’]) && !empty($atts[‘text’])) { $sco_array[$dropid][$atts[‘value’]] = $atts[‘text’]; } } add_shortcode(‘sco’,’dropdown_option’); function sc_dropdown($atts) { $id = … Read more

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