How can I included CSS to a page or a shortcode? [closed]

Simply follow the link to the has_shortcode() documentation in the last answer to the duplicate question. There you’ll find: function custom_shortcode_scripts() { global $post; if ( is_a( $post, ‘WP_Post’ ) && has_shortcode( $post->post_content, ‘custom-shortcode’) ) { wp_enqueue_script( ‘custom-script’); } } add_action( ‘wp_enqueue_scripts’, ‘custom_shortcode_scripts’); For styles this would be: function custom_shortcode_styles() { global $post; if ( … Read more

How to set Contact Form 7 fields default value using shortcode attribute? [closed]

the destination-email attribute requires an additional filter to be hooked to work, as detailed in cf7 doc and this forum thread, you need to ensure you do the following 4 steps: 1) in addition to the short code attribute, [contact-form-7 id=”123″ title=”Contact Form” destination-email=”[email protected]”] 2) you need to, add_filter( ‘shortcode_atts_wpcf7’, ‘custom_shortcode_atts_wpcf7_filter’, 10, 3 ); function … Read more

custom shortcode will not display the wrapped content

Because the shortcode must return a string. Avoid using the “echo” function in shortcode. Instead of doing that: function my_shortcode_function($content){ echo ‘<div class=”wrap”>’; echo ‘<div class=”col”>’.$content.'</div>’; echo ‘</div>’; } Do that: function my_shortcode_function($content){ $shortcode_return = ‘<div class=”wrap”>’; $shortcode_return .= ‘<div class=”col”>’.$content.'</div>’; $shortcode_return .= ‘</div>’; return $shortcode_return; } Or use object buffering: function my_shortcode_function($content){ ob_start(); ?> … Read more

Shortcode Inside Class Not Working

if you use any hooks, filters or shortcodes with class methods, you have three options. either declare it in the context of an instance, in which case, you can refer to the instance of the class. class myClass { function __construct() { add_shortcode(‘my_shortcode_name’, [ $this, ‘shortcode’ ]); } function shortcode() { //your code here //properties … Read more

Wrap shortcode inside custom block

First Add a normal Shortcode block and type the shortcode [foo]123[/foo] Then click More Options for the block and select Add to Reusable Blocks Then provide a name as Foo Next, time you can search and add the Foo block instead of typing the shortcode Thanks

Executing a shortcode from a “normal” text/hyperlink

Yes and no I created a shortcode named foo: add_shortcode( ‘foo’, ‘fooshort’ ); function fooshort( $atts ) { return “https://google.com”; } Then put this in a post: test [foo] The result: test https://google.com So if I take your question literally, yes, you can put shortcodes in anchor attributes. But the shortcode has no idea it’s … Read more

Template part inside shortcode, unexpected reult

The get_template_part() function doesn’t assume any directory name, you have to explicitly supply it. It’s also relative to the active theme directory. So in many of your examples it was looking for the template in the root of your active theme. The correct format would be: get_template_part( ‘template-parts/test-one’ ); If you wanted to, you could … Read more