How to create ShortCode

You need to use hooks to create custom columns and data for a custom post type are manage_{$post_type}posts_columns and manage{$post_type}_posts_custom_column respectively. {$post_type} is the name of the custom post type. I have created common function to add column and and their data. You can use below function to add column and it’s data. function cv_add_column_to_admin_dashboard($column_title, … Read more

How to include any template using Shortcode fuction?

You can’t return the include statement. And you shouldn’t use include template parts. And here’s how to do it correctly: function custom_code() { ob_start(); get_template_part( ‘custom-template.php’ ); return ob_get_clean(); } add_shortcode( ‘custom_shortcode’, ‘custom_code’ ); So what we’re doing here is: Start output buffering. Include given template part using get_template_part function. Return all the output generated … Read more

Can I use shortcodes in mail body

The shortcode generation should output a string, so that should in theory be possible if you know and trust the shortcode’s output. But many shortcodes are generated with the front-end in mind and within the loop context, so the mail context might not always work though, if they depend on conditional checks like is_single(). There … Read more

related articles using shortcodes

The best way to add the shortcode is to create a shortcode in your child theme functiuons.php file. function footag_func( $atts ) { //Example return “foo = {$atts[‘foo’]}”; } add_shortcode( ‘footag’, ‘footag_func’ ); You can refer to this document for WordPress shortcodes detail https://codex.wordpress.org/Function_Reference/add_shortcode

Default WordPress shortcodes not working?

[display-posts] is not a default shortcode that’s included in the WordPress software. It is, however, part of the WordPress.com hosted service. You can read more about the differences between the two here. So the reason the shortcode is not working is because you don’t have a WordPress.com hosted site (I can tell because .com would … Read more

How to add a same div on every page

If a child theme does not have a file (i.e. page.php), WordPress looks in the parent theme for that file. That’s much of the reason for how child themes exist – to override specific content of the parent, but not to override anything else. So in this case you are wanting to add an additional … Read more

Turning variable into a value set in shortcode

I want the $icon variable to become the value of icon attribute of custom-link I set: If I understood your question correctly, this is what you want, function custom_link($atts, $custom_title) { include “PATH_TO_YOUR_PHP_FILE_CONTAINING_ICON_VARS”; $url = $atts[‘url’]; $color = $atts[‘color’]; $icon = $atts[‘icon’]; $icon = $$icon; // $$icon is $icon_paypal return ‘<a class=”button-round custom-link” style=”background-color: ‘ … Read more