WordPress
October 12, 2021

How to Create Your Own WordPress Shortcodes

Simple shortcodes

Shortcode functions can be added to plugin code or your theme’s functions.php file. If it’s the latter, I’d recommend creating a separate wc-shortcodes.php file, then adding include(‘wc-shortcodes.php’); to functions.php. You can use below code to include file wc-shortcodes.php.

If the shortcode produces a lot of HTML then ob_start can be used to capture output and convert it to a string as follows:-

Parameterized shortcodes

‘something’,
‘bar’ => ‘something else’,
), $atts );

return “foo = {$a[‘foo’]}”;
}

?>

This creates a “[bartag]” shortcode that supports two attributes: [“foo” and “bar”]. Both attributes are optional and will take on default options [foo=”something” bar=”something else”] if they are not provided. The shortcode will return as foo = {the value of the foo attribute}.

Related Post


How to Create Custom Post Type in WordPress

Custom post types are same like posts and pages. By default WordPress comes with a few different post types which are all stored in the database under the wp_posts table. Default Post Types Posts Pages Attachments Revisions Navigation Menus Custom CSS Changesets We can create your own custom post types and call them whatever we […]

Mobile Menu Collapse Effect Divi

Right Now Divi is not providing collapse effect for mobile menu. So when we have many items its hard to manage menu on mobile. It’s a great way to customize the Divi mobile menu using CSS and jQuery. You have to put following code on your css and js files. Put below code on any […]

Create Nested Repeater Meta Box in WordPress

Nested Repeatable Custom Fields in a Meta box Creating a “nested repeater meta-box” without a Plugin in WordPress. Add below code in your functions.php file (this file is located in your theme folder): Use below code to show metabox values from anywhere

How to Add Excerpts to Your Pages in WordPress

you will need to add the following code to your current themes functions.php file

Redirect to Checkout after add to cart WooCommerce

Redirecting the user to the checkout page when they’ve added a product to their cart. This may come in handy if you only sell one product / one product per time. The filter woocommerce_add_to_cart_redirect makes it easy to redirect user to custom page. Code goes in function.php file of your active child theme (or active […]

Prevent svg translation of fontawesome icon

Add Following script in head so use below code in your current themes header.php file. And also you have to add following script before your fontawesome css link.


Leave a Reply

Your email address will not be published. Required fields are marked *