Page Builder: Live Composer Shortcodes

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

Before starting, here is an overview of the Page Builder: Live Composer Plugin and the shortcodes it provides:

Plugin Icon
Page Builder: Live Composer

"Page Builder: Live Composer is a versatile WordPress plugin that allows you to design and customize your web pages in real-time. With its user-friendly interface, creating stunning web pages is a seamless process."

★★★★✩ (199) Active Installs: 10000+ Tested with: 6.1.4 PHP Version: false
Included Shortcodes:
  • [dslc_page_title]
  • [dslc_bloghome]
  • [dslc_authorbio]
  • [dslc_commentscount]
  • [dslc_archive_heading]
  • []
  • [dslc_prevpost_url]
  • [dslc_postpagination]

Page Builder: Live Composer [dslc_page_title] Shortcode

The Live Composer Page Builder plugin shortcode, ‘dslc_page_title’, is designed to display the title of any page. This shortcode retrieves the title of the current page using the WordPress function ‘the_title()’. It returns the title as a string without any link or formatting, making it ideal for headers or title sections.

Shortcode: [dslc_page_title]

Examples and Usage

Basic example – The following shortcode allows you to display the title of the current page.

[dslc_page_title /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'dslc_page_title', 'dslc_sc_page_title' );

Shortcode PHP function:

function dslc_sc_page_title() {
	$output = the_title( '', '', false );
	return $output;
}

Code file location:

live-composer-page-builder/live-composer-page-builder/includes/shortcodes.php

Page Builder: Live Composer [dslc_bloghome] Shortcode

The Live Composer Page Builder’s shortcode ‘dslc_bloghome’ is designed to return the sanitized home URL of your blog. This shortcode utilizes PHP’s sanitize_url and esc_url functions to ensure a safe and valid URL.

Shortcode: [dslc_bloghome]

Examples and Usage

Basic example – The shortcode ‘dslc_bloghome’ is used to display the home URL of the blog.

[dslc_bloghome /]

Advanced examples

Let’s assume we want to modify the shortcode to accept parameters for protocol (http or https) and a boolean for whether to include ‘www’ or not. We can modify the function as follows:


function dslc_bloghome_shortcode($atts) {
    $atts = shortcode_atts(
        array(
            'protocol' => 'http',
            'www' => 'false',
        ), $atts, 'dslc_bloghome'
    );
    
    $url = $atts['protocol'] . '://';
    
    if($atts['www'] == 'true') {
        $url .= 'www.';
    }
    
    $url .= sanitize_url(esc_url(home_url()));
    
    return $url;
}
add_shortcode( 'dslc_bloghome', 'dslc_bloghome_shortcode' );

Now, you can use this shortcode with parameters like this:

[dslc_bloghome protocol="https" www="true" /]

This will output the blog’s home URL with ‘https’ as the protocol and including ‘www’.

PHP Function Code

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

Shortcode line:

add_shortcode( 'dslc_bloghome', 'dslc_bloghome_shortcode' );

Shortcode PHP function:

function dslc_bloghome_shortcode() {
	// Code
	$output =sanitize_url(esc_url(home_url()));

	return $output;
}

Code file location:

live-composer-page-builder/live-composer-page-builder/includes/shortcodes.php

Page Builder: Live Composer [dslc_authorbio] Shortcode

The Live Composer Page Builder shortcode, ‘dslc_authorbio’, retrieves the author’s bio from the metadata. It displays the author’s description on the webpage. If no description is available, it returns an empty string to prevent the “No content” message. This ensures a seamless user experience.

Shortcode: [dslc_authorbio]

Examples and Usage

Basic example – Display the author’s bio on a post or page using the ‘dslc_authorbio’ shortcode.

[dslc_authorbio /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'dslc_authorbio', 'dslc_sc_authorbio' );

Shortcode PHP function:

function dslc_sc_authorbio() {
	$output = get_the_author_meta( 'description' );

	if ( ! $output ) {
		$output = ' ';
		// to prevent "Looks like there is no content" message
		// in the Live Composer
	}

	return $output;
}

Code file location:

live-composer-page-builder/live-composer-page-builder/includes/shortcodes.php

Page Builder: Live Composer [dslc_commentscount] Shortcode

The ‘dslc_commentscount’ shortcode from Live Composer Page Builder plugin is used to display the number of comments on a post. This shortcode fetches the numeric value of comments and displays it accordingly. If no comments are found, ‘No Comments’ is shown. For multiple comments, it shows the actual number followed by ‘Comments’, and for a single comment, it displays ‘1 Comment’.

Shortcode: [dslc_commentscount]

Examples and Usage

Basic example – A simple usage of the ‘dslc_commentscount’ shortcode to display the number of comments on a post or page.

[dslc_commentscount /]

Advanced examples

In the given PHP code, there are no parameters or attributes defined for the shortcode. However, we can modify the function to accept parameters. Here’s an example where we add a ‘post_id’ parameter to the shortcode. This allows us to display the number of comments for a specific post.


function dslc_sc_commentscount( $atts ) {
    $atts = shortcode_atts( array(
        'post_id' => '',
    ), $atts, 'dslc_commentscount' );

    $num_comments = get_comments_number( $atts['post_id'] ); 

    if ( $num_comments == 0 ) {
        $comments = __( 'No Comments', 'live-composer-page-builder' );
    } elseif ( $num_comments > 1 ) {
        $comments = $num_comments . __( ' Comments', 'live-composer-page-builder' );
    } else {
        $comments = __( '1 Comment', 'live-composer-page-builder' );
    }

    $output = $comments;

    return $output;
}
add_shortcode( 'dslc_commentscount', 'dslc_sc_commentscount' );

With this modification, you can use the shortcode like this to display the number of comments for the post with ID 123:

[dslc_commentscount post_id=123 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'dslc_commentscount', 'dslc_sc_commentscount' );

Shortcode PHP function:

function dslc_sc_commentscount() {
	$num_comments = get_comments_number(); // get_comments_number returns only a numeric value

	if ( $num_comments == 0 ) {
		$comments = __( 'No Comments', 'live-composer-page-builder' );
	} elseif ( $num_comments > 1 ) {
		$comments = $num_comments . __( ' Comments', 'live-composer-page-builder' );
	} else {
		$comments = __( '1 Comment', 'live-composer-page-builder' );
	}

	$output = $comments;

	return $output;
}

Code file location:

live-composer-page-builder/live-composer-page-builder/includes/shortcodes.php

Page Builder: Live Composer [dslc_archive_heading] Shortcode

The Live Composer Page Builder shortcode, ‘dslc_archive_heading’, dynamically generates headings based on the type of archive page being viewed. It displays different headings for categories, tags, author archives, daily, monthly, and yearly archives. It also handles post formats and search results, providing a unique heading for each scenario.

Shortcode: [dslc_archive_heading]

Examples and Usage

Basic example – A simple usage of the ‘dslc_archive_heading’ shortcode, which will display the archive heading based on the current page context. It could be a category, tag, author, date, post format, or search result page.

[dslc_archive_heading /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'dslc_archive_heading', 'dslc_archive_heading_shortcode' );

Shortcode PHP function:

function dslc_archive_heading_shortcode() {

	$output = '';

	if ( DS_LIVE_COMPOSER_ACTIVE ) :
		$output .= __( 'This heading will be automatically generated by a theme', 'live-composer-page-builder' );

	elseif ( is_category() ) :
		$output .= sprintf( __( 'Category Archives: %s', 'live-composer-page-builder' ), '<span>' . single_cat_title( '', false ) . '</span>' );

	elseif ( is_tag() ) :
		$output .= sprintf( __( 'Tag Archives: %s', 'live-composer-page-builder' ), '<span>' . single_tag_title( '', false ) . '</span>' );

	elseif ( is_author() ) :
		/* Queue the first post, that way we know
		 * what author we're dealing with (if that is the case).
		*/
		the_post();
		$output .= sprintf( __( 'Author Archives: %s', 'live-composer-page-builder' ), '<span class="vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" title="' . esc_attr( get_the_author() ) . '" rel="me">' . get_the_author() . '</a></span>' );
		/* Since we called the_post() above, we need to
		 * rewind the loop back to the beginning that way
		 * we can run the loop properly, in full.
		 */
		rewind_posts();

	elseif ( is_day() ) :
		$output .= sprintf( __( 'Daily Archives: %s', 'live-composer-page-builder' ), '<span>' . get_the_date() . '</span>' );

	elseif ( is_month() ) :
		$output .= sprintf( __( 'Monthly Archives: %s', 'live-composer-page-builder' ), '<span>' . get_the_date( 'F Y' ) . '</span>' );

	elseif ( is_year() ) :
		$output .= sprintf( __( 'Yearly Archives: %s', 'live-composer-page-builder' ), '<span>' . get_the_date( 'Y' ) . '</span>' );

	elseif ( is_tax( 'post_format', 'post-format-aside' ) ) :
		$output .= __( 'Asides', 'live-composer-page-builder' );

	elseif ( is_tax( 'post_format', 'post-format-image' ) ) :
		$output .= __( 'Images', 'live-composer-page-builder' );

	elseif ( is_tax( 'post_format', 'post-format-video' ) ) :
		$output .= __( 'Videos', 'live-composer-page-builder' );

	elseif ( is_tax( 'post_format', 'post-format-quote' ) ) :
		$output .= __( 'Quotes', 'live-composer-page-builder' );

	elseif ( is_tax( 'post_format', 'post-format-link' ) ) :
		$output .= __( 'Links', 'live-composer-page-builder' );

	elseif ( is_tax() ) :
		$output .= sprintf( __( 'Category Archives: %s', 'live-composer-page-builder' ), '<span>' . single_cat_title( '', false ) . '</span>' );

	elseif ( is_search() ) : // special title for search result page
		// get number of posts found for search query
		global $wp_query;
		$search_results_count = $wp_query->found_posts;

		$output .= __( 'You are searching for: ', 'live-composer-page-builder' );
		$output .= '<strong>' . get_query_var( 's' ) . '</strong>. <br />';

		if ( 1 == $search_results_count ) {
			$output .= __( 'There is one post that match your criteria...', 'live-composer-page-builder' );
		} elseif ( 1 < $search_results_count ) {
			$output .= sprintf( __( 'Here are %s posts that match your criteria...', 'live-composer-page-builder' ), '<span>' . $search_results_count . '</span>' );
		} else {
			$output .= __( 'Looks like nothing was found. Sorry.', 'live-composer-page-builder' );
		}

	elseif ( is_front_page() ) :
		$output .= get_bloginfo( 'description' );

	else :
		$output .= __( 'Archives', 'live-composer-page-builder' );

	endif;

	return $output;
}

Code file location:

live-composer-page-builder/live-composer-page-builder/includes/shortcodes.php

Page Builder: Live Composer [dslc_prevpost_url] Shortcode

The Live Composer Page Builder shortcode, ‘dslc_prevpost_url’, retrieves the URL of the previous post. It allows customization like retrieving posts from the same category or excluding certain categories.

Shortcode: [dslc_prevpost_url]

Parameters

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

  • previous – Determines if the previous post should be retrieved.
  • in_same_cat – Specifies if the post should be in the same category.
  • excluded_categories – Lists the IDs of categories to be excluded.

Examples and Usage

Basic example – Retrieves the URL of the previous post

[dslc_prevpost_url previous=true]

Advanced examples

Retrieves the URL of the previous post in the same category

[dslc_prevpost_url previous=true in_same_cat=true]

Retrieves the URL of the previous post excluding certain categories. The categories are specified by their IDs, separated by commas.

[dslc_prevpost_url previous=true excluded_categories="1,2,3"]

Retrieves the URL of the next post, not necessarily from the same category

[dslc_prevpost_url previous=false]

Retrieves the URL of the next post in the same category, excluding certain categories

[dslc_prevpost_url previous=false in_same_cat=true excluded_categories="1,2,3"]

PHP Function Code

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

Shortcode line:

add_shortcode( 'dslc_prevpost_url', 'dslc_prevpost_url_shortcode' );

Shortcode PHP function:

function dslc_prevpost_url_shortcode( $atts ) {

	// Attributes
		$args = shortcode_atts(
		array(
			'previous'            => true,
			// Whether to retrieve previous or next post.
			'in_same_cat'         => false,
			// Whether post should be in same category. Whether post should be in same category.
			'excluded_categories' => '',
			// Excluded categories IDs.
		),
		$atts
	);
	$previous = (bool)$args['previous'];
	$in_same_cat = (bool)$args['in_same_cat'];
	$excluded_categories = sanitize_key(esc_attr($args['excluded_categories']));

	// Code
	$output = get_permalink( get_adjacent_post( $in_same_cat, $excluded_categories, $previous ) );

	// for your reference:  get_adjacent_post( $in_same_cat, $excluded_categories, $previous )
	return $output;
}

Code file location:

live-composer-page-builder/live-composer-page-builder/includes/shortcodes.php

Page Builder: Live Composer [dslc_postpagination] Shortcode

The Live Composer Page Builder shortcode, ‘dslc_postpagination’, generates pagination for posts. It uses the ‘wp_link_pages’ function to create numbered page links. The shortcode wraps the page numbers in a div container, applying relevant CSS classes for styling. If no pagination is required, it returns a blank space to avoid content absence errors.

Shortcode: [dslc_postpagination]

Examples and Usage

Basic example – The given shortcode displays the pagination links for a post in WordPress.

[dslc_postpagination /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'dslc_postpagination', 'dslc_postpagination_shortcode' );

Shortcode PHP function:

function dslc_postpagination_shortcode() {
	$output = wp_link_pages( array(
		'before' => '<div class="page-links"><span class="page-links__title">' . __( 'Pages:', 'live-composer-page-builder' ) . '</span><span class="page-numbers">',
		'after'  => '</span></div>',
		'echo'   => 0,
	) );

	if ( ! $output ) {
		$output = ' ';
		// to prevent "Looks like there is no content" message
		// in the Live Composer
	}

	return $output;
}

Code file location:

live-composer-page-builder/live-composer-page-builder/includes/shortcodes.php

Conclusion

Now that you’ve learned how to embed the Page Builder: Live Composer 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 *