Div Shortcode

Below, you’ll find a detailed guide on how to add the Div Shortcode to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Div Shortcode Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Div Shortcode Plugin and the shortcodes it provides:

Plugin Icon
Div Shortcode

"Div Shortcode is a helpful WordPress plugin that allows users to easily implement custom 'div' tags into their posts or pages. With its simple interface, organizing your content becomes effortless."

★★★★★ (7) Active Installs: 2000+ Tested with: 4.7.27 PHP Version: false
Included Shortcodes:
  • [div]
  • [end-div]

Div Shortcode [div] Shortcode

The Div-Shortcode plugin shortcode, ‘div’, enables the dynamic creation of ‘div’ elements. It accepts ‘class’ and ‘id’ as attributes, allowing for customization. The shortcode generates an open ‘div’ tag. If a ‘class’ or ‘id’ attribute is provided, it adds them to the ‘div’, enhancing flexibility.

Shortcode: [div]

Parameters

Here is a list of all possible div shortcode parameters and attributes:

  • class – Specifies a CSS class for the div element
  • id – Assigns a unique identifier to the div element

Examples and Usage

Basic example – Here is a simple usage of the ‘div’ shortcode, which does not specify any class or id.

[div /]

Advanced examples

Use the ‘div’ shortcode to create a div with a specific class. This is useful when you want to apply CSS styles to the div.

[div class="my-class" /]

Use the ‘div’ shortcode to create a div with a specific id. This is useful when you want to manipulate the div with JavaScript or target it with CSS.

[div id="my-id" /]

Use the ‘div’ shortcode to create a div with both a class and an id. This allows for greater control over the div’s styling and behavior.

[div class="my-class" id="my-id" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [div] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'div', 'be_div_shortcode' );

Shortcode PHP function:

function be_div_shortcode( $atts ) {

	$atts = shortcode_atts( array(
		'class' => '',
		'id'    => '',
	), $atts, 'div-shortcode' );

	$return = '<div';
	if ( !empty( $atts['class'] ) )
		$return .= ' class="'. esc_attr( $atts['class'] ) .'"';
	if ( !empty( $atts['id'] ) )
		$return .= ' id="'. esc_attr( $atts['id'] ) .'"';
	$return .= '>';
	return $return;
}

Code file location:

div-shortcode/div-shortcode/div-shortcode.php

Div Shortcode [end-div] Shortcode

The ‘end-div’ shortcode is a part of the div-shortcode plugin. It’s designed to end a division or section in your content. Upon execution, it returns ‘

‘, indicating the end of a specific division. This helps structure and organize your webpage for seamless navigation.

Shortcode: [end-div]

Examples and Usage

Basic example – The ‘end-div’ shortcode is used to close a div element in your WordPress posts or pages.

[end-div /]

Advanced examples

Although the ‘end-div’ shortcode doesn’t accept any parameters, it can be used in conjunction with other shortcodes that do. Here’s an example of how you can use it to wrap a gallery shortcode, which does accept parameters, within a div:


[div class="my-custom-class"]

[end-div /]

In the above example, we’re starting a div with the class of ‘my-custom-class’, inserting a gallery with the specified image IDs, and then closing the div with the ‘end-div’ shortcode.

Here’s another example where we’re using the ‘end-div’ shortcode to close a div that contains a contact form shortcode:


[div id="contact-form-container"]
[contact-form-7 id="1234" title="Contact form 1"]
[end-div /]

In this example, we’re starting a div with the ID of ‘contact-form-container’, inserting a Contact Form 7 form with the specified ID and title, and then closing the div with the ‘end-div’ shortcode.

PHP Function Code

In case you have difficulties debugging what causing issues with [end-div] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'end-div', 'be_end_div_shortcode' );

Shortcode PHP function:

function be_end_div_shortcode( $atts ) {
	return '</div>';
}

Code file location:

div-shortcode/div-shortcode/div-shortcode.php

Conclusion

Now that you’ve learned how to embed the Div Shortcode Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

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