as a shortcode within the loop?

Using the the_posts filter: Here’s one idea using the the_posts filter, that fires before setup_postdata() is activated: /** * Replace [nextpage] with <!–nextpage–> through the ‘the_posts’ filter. * * @see http://wordpress.stackexchange.com/a/183980/26350 */ ! is_admin() && add_filter( ‘the_posts’, function( $posts ) { $posts = array_map( function( $p ) { if ( false !== strpos( $p->post_content, ‘[nextpage]’ … Read more

change plugin shortcode function [closed]

you can override the shortcode like this : add_action(“init”, function () { remove_shortcode(“timelinr”); add_shortcode(“timelinr”, function ($atts, $content) { // call the shortcode of jqueryTimelinrLoad $result = $GLOBALS[“jqueryTimelinrLoad”]->shortcode($atts, $content); // dequeue style wp_dequeue_style(“timelinr-style”); // enqueue your style wp_enqueue_style(“timelinr-style2”, “new.css”); // result of the shortcode return $result; }); });

shortcode not working [closed]

I may have found the problem (from product_attribute) array( ‘per_page’ => ’12’, ‘columns’ => ‘4’, ‘orderby’ => ‘title’, ‘order’ => ‘asc’, ‘attribute’ => ‘asc’, ‘filter’ => ‘asc’ ) [product_attribute attribute=”color” filter=”black”] Notice the attibute is in single quotes wheras yours is in double quotes: do_shortcode (‘[product_attribute attribute=”Grams”]’); also you may need it to be in … Read more

Pros and cons of actions over shortcodes

Neither are correct. Just use show_foo(): <?php echo show_foo(); ?> The only reason to ever use shortcodes is to insert dynamic content into a page or post from within the editor (Although, these days the ‘proper’ way to do that would be with a block, although that’s more difficult). Shortcodes should not be used for … Read more

Shortcode with custom content attribute?

The second parameter of your shortcode function is the content. So rewrite the function: function shortcode_call_to_action( $attributes = NULL, $content=”” ) { $stylesheetdir = get_bloginfo(‘stylesheet_directory’); if ( ” === $content ) { // use a default text if there is no content $content=”default text”; } return “<div id=’call_to_action’> <img src=”https://wordpress.stackexchange.com/questions/58438/$stylesheetdir/images/call_to_action.jpg” alt=”” /> <p>$content</p>”; } If … Read more

Pass $this to function nested in another public function of the same class

There are multiple ways to accomplish this. I’m showing you a way that will not fundamentally change how you are doing it: First in My_Plugin class: class My_Plugin { // … private function define_public_hooks() { $plugin_public = new My_Plugin_Public( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( ‘init’, $plugin_public, ‘init’ ); // … } // … } Then in … Read more

Passing a shortcode attribute to a sub-function

There are different ways to get the result. You can use a class, store the div content in a class or instance variable and output it when needed. As alternative you can use a function with a static variable, to hold the content. I’ll use this second alternative, converting it in a class is an … Read more

Use content custom filter for all shortcodes

so I would like to execute a filter or something that works on every shortcode Looks like you’re after do_shortcode_tag. It “Filters the output created by a shortcode callback.”. Aurovrata Venet gives a demo usage similar to: add_filter( ‘do_shortcode_tag’,function ($output, $tag, $attr){ //make sure it is the right shortcode if(‘aShortcode’ != $tag){ return $output; } … Read more