Default WordPress shortcodes not working?

[display-posts] is not a default shortcode that’s included in the WordPress software. It is, however, part of the WordPress.com hosted service. You can read more about the differences between the two here. So the reason the shortcode is not working is because you don’t have a WordPress.com hosted site (I can tell because .com would … Read more

How to add a same div on every page

If a child theme does not have a file (i.e. page.php), WordPress looks in the parent theme for that file. That’s much of the reason for how child themes exist – to override specific content of the parent, but not to override anything else. So in this case you are wanting to add an additional … Read more

Turning variable into a value set in shortcode

I want the $icon variable to become the value of icon attribute of custom-link I set: If I understood your question correctly, this is what you want, function custom_link($atts, $custom_title) { include “PATH_TO_YOUR_PHP_FILE_CONTAINING_ICON_VARS”; $url = $atts[‘url’]; $color = $atts[‘color’]; $icon = $atts[‘icon’]; $icon = $$icon; // $$icon is $icon_paypal return ‘<a class=”button-round custom-link” style=”background-color: ‘ … Read more

wp_editor not rendering the shortcode

You have to explicitly add shortcode evaluation to a text field for it to work. By default it is only defined for the_content and the_excerpt. If you look at the source of the first one you see this line: $content = apply_filters( ‘the_content’, $content ); Among the default filters is this one: add_filter( ‘the_content’, ‘do_shortcode’, … Read more

WordPress User ID as Shortcode

From add_shortcode …Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results… Try changing the echos in your callback to returns and see, if that helps.

Custom shortcode to display posts, first post is full

There are several issues in your code. Like, syntax error in line 4. Undefined $out variable PHP notice. And main issue is that you are not using the loop properly. In foreach, you need to use setup_postdata() and it also needs to be reset properly. Please check following. add_shortcode( ‘custom-home-posts’, function ( $atts ) { … Read more

how can i pass this attribute in this shortcode?

You haven’t properly output them. You’ve closed the PHP tags after this: ), $atts));?> But, if you want to output a PHP variable you need to open them again, otherwise the text will just be interpreted as HTML. You also need to explicitly echo it. So, for $catheading as an example, you need to output … Read more

Shortcode don’t work in custom option field, any solution?

If you have a shortcode string saved, try echoing it with do_shortcode function, which turns shortcodes into content. $saved_shortcode = get_option( ‘my_customizer’, ‘copyright’ ); if ( $saved_shortcode && is_string( $saved_shortcode ) ) { echo do_shortcode( $saved_shortcode ); } More about the function on the developer handbook, https://developer.wordpress.org/reference/functions/do_shortcode/ EDIT Another option is just echo the year … Read more

Regenerating WordPress shortcodes based on value with AJAX

In order to change the shortcode value by leveraging ajax, you need to modify the PHP code and jQuery as mentioned below: function table_generator() { // Set product providers $providers = array( ‘Provider 1’, ‘Provider 2’, ‘Provider 3’, ); // Build provider selection form $output .= ‘<form id=”submitProvider” action=”” method=”POST”>’; $output .= ‘<select name=”provider_list”>’; $output … Read more