WordPress shortcode doesn’t working on HomePage

Depending on what post editor you are using: Classic – make sure to switch the editor to “Text” instead of “Visual”. The latter will output anything you write in a form of text, while the first one will process the shortcode. Gutenberg – find a plus sign in the top-left area of your WordPress dashboard … Read more

the_widget() and widget’s ID

I believe @One Trick Pony was right. Shortcode widgets have no ID, so I’ve found a way around. Firstly I used PHP rand function: $var = rand(); And then added the “var” to the ID, so it doesn’t collide with other shortcodes calling the same widget (each one has different random number at the end … Read more

Add page title as a javacript variable to specific posts

Use a shortcode. In your plugin or theme (functions.php) add: add_action( ‘after_setup_theme’, ‘wpse_42534_add_permalink_shortcode’ ); function wpse_42534_add_permalink_shortcode() { add_shortcode( ‘permalink’, ‘get_permalink’ ); } Now, your users can use the string [permalink] anywhere in the post to print the URI to the current post or page. Oh, and welcome to WordPress Stack Exchange!

Conditionally loading Facebook PHP SDK in shortcode

You can try to use the_posts filter to search for you shortcode and require the sdk, something like this: function has_my_FB_shortcode($posts) { if ( empty($posts) ) return $posts; $found = false; foreach ($posts as $post) { if ( stripos($post->post_content, ‘[my_shortcode’) ){ $found = true; break; } } if ($found) require(‘path/to/facebook_sdk.php’); return $posts; } add_action(‘the_posts’, ‘has_my_FB_shortcode’);

How to load shortcode sooner

$myfunction= ‘[bc_user_groups amount=”20″]’; $myfunction_parsed = do_shortcode($myfunction); became $atts = array( ‘amount’ => 20 ); $myfunction_parsed = bc_user_groups( $atts ); Call the shortcode function (I asume your shortcode function name is ‘bc_user_groups’) direct.

Pagination in a Shortcode. Get_next_posts_link not working but get_previous_posts_link works fine right next to it

This is an old question, but I needed the answer to this one as well. Here is the solution taken right from the WP codex… $prev = ‘<div class=”nav-previous”>’ . get_next_posts_link( __( ‘<span class=”meta-nav”>&larr;</span> Previous’ ), $loop->max_num_pages ); You need to append the max_num_pages parameter from the query to your output and it should work … Read more