Hot answers tagged

4

Try the filters in your functions.php: add_filter( 'the_excerpt', 'shortcode_unautop'); add_filter( 'the_excerpt', 'do_shortcode'); Props: @bainternet (Source) Or, use your own filter on get_the_excerpt. Put this in your theme's functions.php: function custom_excerpt($text = '') { $raw_excerpt = $text; if ( '' == $text ) { $text = ...


4

I wonder if you could override the [rev_slider] with this kind of wrapper: add_shortcode( 'rev_slider', function( $atts = array(), $content = '' ) { $html = ''; // Your custom banner HTML $banner = '<div id="bannerHTML"><!-- banner HTML goes here --></div>'; // Append your banner HTML to the revslider's output if( ...


2

This is a solution I've come up with after refining it a bit. The below should only run if the shortcode exists in the content. It loops through all the shortcodes to find the specific one we need, replaces it with the shortcode plus the new HTML: function insert_after_shortcode( $content ) { if( ! has_shortcode( $content, 'shortcode_name' ) ) { ...


2

This happens when there is echoed output from the shortcode rather than the result being returned... I'd wager nt_course_note_entry_field likely echoes rather than returns. If there is one - or you can create one) - use a similar function like nt_get_course_note_entry_field that does not echo. If you can't change the function you can wrap it in an output ...


2

the_permalink(), the_title() by default echo their value. As you want to store that value in a variable you will need to return the values instead. get_the_permalink(), get_the_title() are two similar functions that return the value instead of echo. So you new code may look something like this: $list = '<li class="ubermenu-submenu ubermenu-submenu-id-...


2

As you are using URLs from oEmbed provides (YouTube, Vimeo, Soundcloud, etc), I would use wp_oembed_get() function. This function uses oEmbed and tries to get the embed HTML of the provided URL. $embed = wp_oembed_get( $some_url ); if( $embed ) { echo $embed; } else { // The embed HTML couldn't be fetched }


2

I would not use custom fields or shortcodes for this functionality, I would look at filters. the_content filter and the loop_end action (just make sure that your theme uses while ( have_posts() ) in single post pages) comes to immediate mind here. These are two options which requires no modification of any of your files in your theme. This way you can add ...


1

First, check the quotes: <?php echo do_shortcode('[enlarge_text small="A" medium="A" large="A" default_value="medium"]'); ?>


1

Don't remember exactly when (4.3?) core had gone with a much more restrictive parsing of shortcodes due to many security problems that the lax parsing with combination of poorly implemented shortcodes had created. The end result is that you can not use a shortcode in an attribute. The right solution is to have a shortcode that produces the whole iframe. ...


1

Quickest way is actually to make a standalone php file (wrap the code in <?php CODE ?> and save it in your /wp-content/mu-plugins/ directory, eg, I often use a site-shortcodes.php... WordPress will auto-load the file, and your functionality will be independent of the theme you use. otherwise if the functionality is tied in to your theme specifically ...


1

There are several aspects and as always, performance is something that have to be taken in a context. Pieter's answer gives you one - "do you even have a (better) way to achieve the required functionality". going beyond that, there are some facts that is worth to keep in mind Modern PHP is fast. It is never a good thing to write inefficient code but it is ...


1

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 useful and usally outweigh the fact ...



Only top voted, non community-wiki answers of a minimum length are eligible