esc_attr not working in shortcode

I think I have figured out the problem, though I have yet to solve it. I am running the shortcode in a WP Types custom WYSIWYG field. The shortcode works perfectly everywhere else, including directly in my theme files and in the native WordPress content WYSIWYG, so it seems it is a bug in WP … Read more

Adding shortcode to the main menu

I thought about making this a plugin since so many people ask about it, but here’s what you can do. This is by far the most consistent option that I’ve found because it allows you to do virtually anything you want in menus and doesn’t require writing your own walker class. Install stag custom sidebars … Read more

Extending the Audio Shortcode

I would use the filter wp_audio_shortcode: /** * Filter the audio shortcode output. * * @since 3.6.0 * * @param string $html Audio shortcode HTML output. * @param array $atts Array of audio shortcode attributes. * @param string $audio Audio file. * @param int $post_id Post ID. * @param string $library Media library used for … Read more

Shortcodes: Pros and Cons

An alternative you have not mentioned is to customize the shortcode experience, since shortcodes are a UX failure for the end user. Create a specific shortcode button on the editor so the user can select text and click an actual button. You can go further and attach some code to error check what the user … Read more

Hide Post comments when displayed via WP_Query

The problem You must remember to call the core function wp_reset_postdata(), after your while loop, to restore the global $post object. The comment form is relying on that object, that you override with your $queryPosts->the_post() call. Note that the extract() isn’t recommended, check this answer by @toscho, for example. Removing comments To remove the comment … Read more

Adding PHP/HTML code inside page from custom template

This is how to code the shortcode function foobar_func( $atts ){ return “foo and bar”; } add_shortcode( ‘foobar’, ‘foobar_func’ ); And to execute a function using output buffering add_shortcode( ‘shortcode_tag’, ‘function_name’ ); function function_name($atts) { ob_start(); // Add your code $var = ob_get_contents(); ob_end_clean(); return $var; }