Smart Custom 404 Shortcode

Below, you’ll find a detailed guide on how to add the Smart Custom 404 error page [404page] Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Smart Custom 404 error page [404page] Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Smart Custom 404 error page [404page] Plugin and the shortcodes it provides:

Plugin Icon
Smart Custom 404 error page [404page]

"Smart Custom 404 Error Page (404page) is a WordPress plugin that allows users to easily create and manage customized 404 error pages, enhancing visitor experience on broken or dead links."

★★★★☆ (1179) Active Installs: 100000+ Tested with: 6.3.2 PHP Version: 5.4
Included Shortcodes:
  • [pp_404_url]

Smart Custom 404 error page [pp_404_url] Shortcode

The 404page plugin shortcode ‘pp_404_url’ is designed to fetch and return the URL of the 404 error page. It accepts a parameter ‘type’ which can be ‘page’, ‘domainpath’, or any other value. Depending on the ‘type’, it returns the 404 page URL path, the host plus path, or the full URL respectively.

Shortcode: [pp_404_url]

Parameters

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

  • page – Retrieves the path of the 404 error page.
  • domainpath – Fetches the domain and path of the 404 error page.
  • full – Provides the full URL of the 404 error page.

Examples and Usage

Basic example – The following example demonstrates the basic usage of the shortcode, which will return the full URL of the 404 page.

[pp_404_url]

Advanced examples

Here, we are using the shortcode with the ‘page’ parameter to get the URL path of the 404 page. The ‘page’ parameter only returns the path of the URL without the domain.

[pp_404_url type='page']

In this next example, we are using the ‘domainpath’ parameter to get the host and path of the 404 page URL. This parameter returns the URL with the domain but without the protocol (http or https).

[pp_404_url type='domainpath']

These examples demonstrate the flexibility of the ‘pp_404_url’ shortcode, allowing you to retrieve the URL of your 404 page in different formats based on your specific needs.

PHP Function Code

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

Shortcode line:

add_shortcode( 'pp_404_url', 'pp_404_get_the_url' );

Shortcode PHP function:

function pp_404_get_the_url( $type ) {

	$url = '';
	
	if ( is_array( $type ) ) {
		
		$type = $type[0];
		
	}
	
	if ( 'page' == $type ) {
	  
		$url = trim( pp_404page()->get_404_url( 'path' ), '/' );
	  
	} elseif ( 'domainpath' == $type ) {
	
		$url = pp_404page()->get_404_url( 'host' ) . pp_404page()->get_404_url( 'path' );
	  
	} else {
		
		$url = pp_404page()->get_404_url( 'full' );
	  
	}
  
  
	return $url;
	
}

Code file location:

404page/404page/shortcodes.php

Conclusion

Now that you’ve learned how to embed the Smart Custom 404 error page [404page] Plugin shortcode, 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 *