One Page Express Companion Shortcodes

Below, you’ll find a detailed guide on how to add the One Page Express Companion 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 One Page Express Companion Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the One Page Express Companion Plugin and the shortcodes it provides:

Plugin Icon
One Page Express Companion

"One Page Express Companion is a WordPress plugin designed to enhance the functionality and design of your one-page websites. It offers a variety of customization options to give your page a unique and professional look."

★★★★☆ (10) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [one_page_express_latest_news]
  • [one_page_express_blog_link]
  • [one_page_express_contact_form]

One Page Express Companion [one_page_express_latest_news] Shortcode

The ‘one_page_express_latest_news’ shortcode is a dynamic tool that displays the latest news posts on your website. It adjusts the number of posts shown based on the column settings. This shortcode generates a section with post thumbnails, titles, excerpts, and a ‘Read More’ button. It also includes a post footer. It’s a great way to keep your visitors updated with the latest news.

Shortcode: [one_page_express_latest_news]

Examples and Usage

Basic example – Displays the latest news posts in a grid layout. The number of columns in the grid is determined by the ‘one_page_express_latest_news_columns’ theme setting. By default, it is set to 4 columns.

[one_page_express_latest_news]

PHP Function Code

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

Shortcode line:

add_shortcode( 'one_page_express_latest_news', 'one_page_express_latest_news' );

Shortcode PHP function:

function one_page_express_latest_news() {
	ob_start(); ?>
	<?php
	$recentPosts = new WP_Query();
	$cols        = intval( \OnePageExpress\Companion::getThemeMod( 'one_page_express_latest_news_columns', 4 ) );

	$post_numbers = 12 / $cols;

	add_filter( 'excerpt_length', 'one_page_express_latest_news_excerpt_length' );
	add_filter( 'excerpt_more', 'one_page_express_latest_excerpt_more' );
	$recentPosts->query( 'showposts=' . $post_numbers . ';post_status=publish;post_status=publish;post_type=post' );
	while ( $recentPosts->have_posts() ) :
		$recentPosts->the_post();
		?>
		<div id="post-<?php the_ID(); ?>" class="blog-postcol cp<?php echo esc_attr( $cols ); ?>cols">
			<div class="post-content">
				<?php if ( has_post_thumbnail() ) : ?>
					<a class="post-list-item-thumb" href="<?php the_permalink(); ?>">
						<?php the_post_thumbnail(); ?>
					</a>
				<?php endif; ?>
				<div class="row_345">
					<h3 class="blog-title">
						<a href="<?php the_permalink(); ?>" rel="bookmark">
							<?php the_title(); ?>
						</a>
					</h3>
					<?php the_excerpt(); ?>
					<a class="button blue small" href="<?php echo get_permalink(); ?>">
						<span data-theme="one_page_express_latest_news_read_more"><?php \OnePageExpress\Companion::echoMod( 'one_page_express_latest_news_read_more', 'Read more' ); ?></span>
					</a>
					<?php get_template_part( 'template-parts/content-post-footer' ); ?>
				</div>
			</div>
		</div>
		<?php
	endwhile;
	wp_reset_postdata();

	remove_filter( 'excerpt_length', 'one_page_express_latest_news_excerpt_length' );
	remove_filter( 'excerpt_more', 'one_page_express_latest_excerpt_more' );
	$content = ob_get_contents();
	ob_end_clean();

	return $content;
}

Code file location:

one-page-express-companion/one-page-express-companion/theme-data/one-page-express/functions.php

One Page Express Companion [one_page_express_blog_link] Shortcode

The One Page Express Companion plugin shortcode is a tool that generates a link to the blog page. It checks if your homepage displays your latest posts or a static page. If it’s a static page and a separate posts page is set, it returns the URL of the posts page. If not, it generates a URL that lists all posts. If your homepage is your latest posts, it simply returns the URL of the homepage.

Shortcode: [one_page_express_blog_link]

Examples and Usage

Basic example – The following shortcode is used to fetch the URL of the blog page.

[one_page_express_blog_link /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'one_page_express_blog_link', 'one_page_express_blog_link' );

Shortcode PHP function:

function one_page_express_blog_link() {
	if ( 'page' == get_option( 'show_on_front' ) ) {
		if ( get_option( 'page_for_posts' ) ) {
			return esc_url( get_permalink( get_option( 'page_for_posts' ) ) );
		} else {
			return esc_url( home_url( '/?post_type=post' ) );
		}
	} else {
		return esc_url( home_url( '/' ) );
	}
}

Code file location:

one-page-express-companion/one-page-express-companion/theme-data/one-page-express/functions.php

One Page Express Companion [one_page_express_contact_form] Shortcode

The One Page Express Companion plugin shortcode is designed to embed a contact form on your page. This shortcode checks if a contact form shortcode is set. If set, it processes and displays the form. If not, it displays a message guiding the user to set the shortcode parameter in the customizer.

Shortcode: [one_page_express_contact_form]

Examples and Usage

Basic example – A simple usage of the shortcode to display a default contact form.

[one_page_express_contact_form]

PHP Function Code

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

Shortcode line:

add_shortcode( 'one_page_express_contact_form', 'one_page_express_contact_form' );

Shortcode PHP function:

function one_page_express_contact_form( $attrs = array() ) {
	$atts = shortcode_atts(
		array(
			'shortcode' => '',
		),
		$attrs
	);
	// compatibility with free //
	$contact_shortcode = get_theme_mod( 'one_page_express_contact_form_shortcode', '' );
	if ( $atts['shortcode'] ) {
		$contact_shortcode = '[' . html_entity_decode( html_entity_decode( $atts['shortcode'] ) ) . ']';
	}
	ob_start();
	if ( $contact_shortcode !== '' ) {
		echo do_shortcode( $contact_shortcode );
	} else {
		echo '<p style="text-align:center;color:#ababab">' . __(
			'Contact form will be displayed here. To activate it you have to click this area and set the shortcode parameter in Customizer.',
			'one_page_express-companion'
		) . '</p>';
	}

	$content = ob_get_contents();
	ob_end_clean();

	return $content;
}

Code file location:

one-page-express-companion/one-page-express-companion/theme-data/one-page-express/functions.php

Conclusion

Now that you’ve learned how to embed the One Page Express Companion 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 *