Shortcode is not outputting all of the desired markup

I just tested this code and it appears to be working. Though as others have stated you are missing a semicolon at the end of margin-bottom, which you may want to add to be semantically correct. With that being said, to get the code to output exactly how you want when entered into the WYSIWYG, … Read more

Automatically add class-attribute to gallery?

If you take a look at native galleries they already have IDs with counter implemented: $instance++; … $selector = “gallery-{$instance}”; … $gallery_div = “<div id=’$selector’class=”gallery… So first gallery within a post will have <div id=”gallery-1″… and so on. This is used by core itself to target different styles at each instance. If you need to … Read more

Object of class WP_Query could not be converted to int inside shortcode

I rewrote the function based on a few other posts I have seen online and now have the following code which works without any errors. I am still open to any further suggestions on the best way to streamline this code even further it it can be. Thanks again function downloads_shortcode($atts){ extract(shortcode_atts(array( ‘download_type’ => ” … Read more

Running Filter or Shortcode Before Query Prevents Excerpt from Showing

It seems you need to rest the post data before return the $postCount. Before return it, add the follow: wp_reset_postdata(); — There is a difference between wp_reset_query()and wp_reset_postdata(), as explained here. wp_reset_query() – ensure that the main query has been reset to the original main query. wp_reset_postdata() – ensures that the global $post has been … Read more

Shortcode to eliminate and replace with

You’ve got the $content available to you in your remove_p function – so inside that function just look for the existence of a special string (i.e. your “shortcode”), to allow the filter to do the str_replace. For example: if ( false !== strpos( $content, “[p-filter]”) ) { $paragraphs = array(“<p>”,”</p>”,”[p-filter]”); $noparagraphs = array(“”,”<br>”,””); return str_replace( … Read more

Shortcode: How to add custom posts?

Correct. post__in requires an array but the id parameter in [video-course limit=8 id=”418, 1186″] is passed in as a string, so in your shortcode, you would have to parse it into an array in order to use it: if ( !is_array($id) ) { // If $id is not an array (not your default value in … Read more

How to take parameters from a function and make them editable as attributes in a shortcode

Essentially you are asking how to pass parameters to a shortcode. This can be done with the function shortcode_atts, which has two required parameters: an array of valid parameters and their defaults, and the attributes of the shortcode that is being passed. You would use it like this: add_shortcode( ‘wpse232385_show_news’, ‘wpse232385_news_query’ ); function wpse232385_news_query ($atts) … Read more

Removing text + shortcode from all posts

Simply follow these steps: Export your database, save a duplicate of it Open the database in a text editor, I use Sublime Search for that [shortcode] and text and remove those (can replace them with a backspace or anything else you want) Save that edited database Create a new database and upload this new data … Read more