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

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; }

Remove and restore one shortcode

Another old unanswered question. Hopefully useful to someone in the future. WordPress stores shortcode tags and callbacks in the $shortcode_tags. This is how I’d do it. function my_the_content( $content ) { global $shortcode_tags; $tag= ‘some_shortcode’; //* Make sure it’s actually a valid shortcode if( ! isset( $shortcode_tags[ $tag ] ) ) { return $content; } … Read more

Shortcode does not work, changes html order

the_post_thumbnail_url() will echo the URL. You should use functions that have get_the_… in the beginning of their names, since functions starting with the_… will generally echo the content. So, your sprintf should use get_the_post_thumbnail_url() like this: $html .= sprintf( ‘<div class=”grid-item”><a href=”https://wordpress.stackexchange.com/questions/278102/%s” title=””>%s</a></div>’, get_the_post_thumbnail_url( get_the_ID(), ‘full’ ), the_title_attribute( ‘echo=0’ ), //get_the_title() //the_post_thumbnail() ); However, in … Read more

Custom Shortcodes Giving error on development site

Initialize the variables first. See code below: function mbiz_tabbed_box( $atts, $content = null ) { extract( shortcode_atts( array( ‘tab1’ => ”, ‘tab2’ => ”, ‘tab3’ => ”, ‘tab4’ => ”, ‘tab5’ => ”, ), $atts ) ); $tab1_button = $tab2_button = $tab3_button = $tab4_button = $tab5_button = ”; if ($tab1) $tab1_button = ‘<li><a href=”#” title=”tab1″>’ … Read more

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