Dynamically create shortcodes using add_shortcode and a callback

the shortcodes doesn’t shop up in the liste because it’s not a valid declaration with a valid function callback on the 2nd argument try this to see what append : // shortcode data add_filter(“shortcode_list”, function ($shortcode_list) { $shortcode_list[“slugA”] = array( “html” => “test html 1”, ); return $shortcode_list; }); add_filter(“shortcode_list”, function ($shortcode_list) { $shortcode_list[“slugB”] = … Read more

WordPress shortcodes & performance

You need to look at this from a couple of perspectives and then you have to weigh the odds against each other In general, shortcodes will be slower (we are talking milliseconds here) as they need to be parsed and processed by the shortcode handler. USAGE: [my_shortcode] in post editor Shortcodes in general are quite … Read more

Can a shortcode function this way

Yes. That result can be achieved by single shortcode function. Here is your code- function paragraph_shortcode( $atts, $content = null ) { $pull_atts = shortcode_atts( array( ‘value’ => 0 ), $atts ); return ‘You are reading paragraph ‘ . wp_kses_post( $pull_atts[ ‘value’ ] ) . ‘: ‘ . do_shortcode($content); } add_shortcode( ‘paragraph’, ‘paragraph_shortcode’ ); It’ll … Read more

How can I get the current user email instead of user ID?

you can get all logged in users details by below function <?php $current_user = wp_get_current_user(); /** * @example Safe usage: $current_user = wp_get_current_user(); * if ( !($current_user instanceof WP_User) ) * return; */ echo ‘Username: ‘ . $current_user->user_login . ‘<br />’; echo ‘User email: ‘ . $current_user->user_email . ‘<br />’; echo ‘User first name: ‘ … Read more

Get list of shortcodes from content

Here’s one way: You can look at has_shortcode() and find the parsing there: preg_match_all( “https://wordpress.stackexchange.com/” . get_shortcode_regex() . “https://wordpress.stackexchange.com/”, $content, $matches, PREG_SET_ORDER ); using the get_shortcode_regex() function for the regex pattern. For non empty matches, you can then loop through them and collect the full shortcode matches with: $shortcodes = []; foreach( $matches as $shortcode … Read more

Nested shortcodes

You cannot use shortcodes like this. The parser would not read that like you want. But there is a workaround: Hijack the shortcode dropbox-foldershare-hyno, run the callback function for the wp-members on the link and pass the result to the original dropbox-foldershare-hyno callback. Sample code, not tested: // wait until the other plugins are loaded … Read more

Adding body class when post contains a specific shortcode

I am doing something like this in one of my plugins: function my_body_class( $c ) { global $post; if( isset($post->post_content) && has_shortcode( $post->post_content, ‘your-shortcode’ ) ) { $c[] = ‘your-class’; } return $c; } add_filter( ‘body_class’, ‘my_body_class’ ); I’m not sure it was really necessary, but I probably can’t remove it now either. TheDeadMedic is … Read more

Passing HTML in WordPress Shortcode arguments

You have used the same quotation characters in 2 different contexts. You should write the shortcode in the following way: [example text=”<a href=”http://example.com”>lorem</a> ipsum”]Lets roll[/example] Then, “unescape” HTML entities on the shortcode output: $return_string = ‘<div class=”some-class”>’. html_entity_decode($text) . $content .'</div>’;

Extending Shortcode attributes

Without seeing your code it is difficult to give you an exact answer. There is the shortcode_atts_{$shortcode} filter that was introduced in WordPress 3.6. All attributes is run through this filter. It has to be noted that the $shortcode parameter needs to be set in shortcode_atts. I haven’t seen shortcodes yet that has this parameter … Read more

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