Pz-LinkCard Shortcode

Below, you’ll find a detailed guide on how to add the Pz-LinkCard 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 Pz-LinkCard Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Pz-LinkCard Plugin and the shortcodes it provides:

Plugin Icon
Pz-LinkCard

"Pz-LinkCard is a dynamic WordPress plugin designed to create attractive link cards within your posts or pages. Its versatile functionality enhances user engagement."

★★★★★ (9) Active Installs: 30000+ Tested with: 6.3.2 PHP Version: 7.0
Included Shortcodes:
  • [pz_linkcard]

Pz-LinkCard [pz_linkcard] Shortcode

The Pz-Linkcard shortcode is a powerful tool in PHP/Wordpress. It handles URL parameters, rectifies URL errors, and converts relative URLs to absolute ones. It also sanitizes and encodes URLs for safe use.

Shortcode: [pz_linkcard]

Parameters

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

  • url – The link address you want to display
  • href – Another way to specify the link address
  • uri – Yet another way to specify the link address
  • ur1 – A fallback for possible typos in specifying the link address
  • title – The title of the link card
  • excerpt – The brief description shown on the link card
  • content – Another way to specify the link card’s description
  • contents – Yet another way to specify the link card’s description
  • description – A fallback for possible typos in specifying the link card’s description

Examples and Usage

Basic example – A simple usage of the pz-linkcard plugin shortcode to display a link card with a specified URL.

[pz_linkcard url="https://example.com"]

Advanced examples

Using the shortcode to display a link card with a specified URL and title. The title will be displayed as the heading of the link card.

[pz_linkcard url="https://example.com" title="Example Website"]

Using the shortcode to display a link card with a specified URL, title, and excerpt. The excerpt will be displayed as the description of the link card.

[pz_linkcard url="https://example.com" title="Example Website" excerpt="This is an example website."]

Using the shortcode to display a link card with a specified URL, and using the content enclosed within the shortcode as the excerpt.

[pz_linkcard url="https://example.com"]This is an example website.[/pz_linkcard]

PHP Function Code

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

Shortcode line:

add_shortcode($this->options['code1'], array($this, 'shortcode' ) );

Shortcode PHP function:

function shortcode($atts, $content = null, $shortcode = null ) {
		// 実行時間
		if	($this->options['debug-mode'] ) {
			if	(function_exists('hrtime' ) ) {
				$start_time		=	hrtime(true ) / 1000;
			} else {
				$start_time		=	microtime(true );
			}
			echo	PHP_EOL.'<!-- Pz-LkC [Debug mode: On] /-->'.PHP_EOL;
			echo	'<!-- Pz-LkC [shortcode]'.PHP_EOL;
			echo	'$atts='.html_entity_decode(print_r($atts, true ) );
			echo	'$content="'.html_entity_decode($content ).'"'.PHP_EOL;
			echo	'$shortcode="'.html_entity_decode($shortcode ).'"'.PHP_EOL;
			echo	'/-->'.PHP_EOL;
		}

		// キーをすべて小文字にする
		// $atts = array_change_key_case($atts, CASE_LOWER);

		// URLパラメータ
		switch	(true) {
		case	(!empty($atts['url'] ) ) :
			$url	=	$atts['url'];
			break;
		case	(!empty($atts['href'] ) ) :				// Aタグのようにhrefパラメータも有効にする
			$url	=	$atts['href'];
			break;
		case	(!empty($atts['uri'] ) ) :				// 密かに記述ミス対応(uriやurIでもurlとして判定する)
			$url	=	$atts['uri'];
			break;
		case	(!empty($atts['ur1'] ) ) :				// 密かに記述ミス対応(ur1でもurlとして判定する)
			$url	=	$atts['ur1'];
			break;
		case	(!empty($atts[0] ) ) :					// 謎の記述ミスに対応
			$url	=	$atts[0];
			break;
		case	(!empty($atts[1] ) ) :					// 謎の記述ミスに対応
			$url	=	$atts[1];
			break;
		default:
			$url	=	null;
			break;
		}

		// 指定されたurlパラメータ(エラー表示用)
		$url_org	=	$url;

		// 相対URLを絶対URLに変換(ショートコードのURLで相対パス表記の場合、内部リンクと見なす)
		if	($this->options['flg-relative-url'] && !mb_strpos($url, '://' ) ) {
			$url	=	$this->pz_RelToURL(esc_url(home_url() ), $url );
		}

		// URLのサニタイズ&エンティティ化
		$url		=	$this->pz_EncodeURL($url ,true );

		// URLエラー
		if	(!$url ) {
			if	(!$this->options['error-mode'] ) {
				$url_now								=	get_permalink();
				$post_id								=	url_to_postid($url_now );
				if	($post_id ) {
					$this->options['error-mode']		=	true;
					$this->options['error-url']			=	$url_now;
					$this->options['error-time']		=	$this->now;
					// オプション更新
					$result	=	$this->pz_UpdateOption();
				}
			}
			$tag		=	'<div class="lkc-card"><div class="lkc-this-wrap"><div class="lkc-info">'.$this->options['plugin-name'].'</div><div class="lkc-excerpt">'.__('-', $this->text_domain ).' '.__('Incorrect URL specification.', $this->text_domain ).'<br>'.__('-', $this->text_domain ).' '.__('URL', $this->text_domain ).'='.html_entity_decode($url_org ).'</div></div></div>';
			$err_info	=	print_r($atts, true );
			return			PHP_EOL.'<div id="lkc-error" class="lkc-error"><!-- '.html_entity_decode($err_info ).' -->'.$tag.'</div>'.PHP_EOL;
		}

		// URLパラメータに編集後のURLを返す
		$atts['url']	=	$url;

		// titleパラメータが無かったらNULLにする
		if	(!isset($atts['title'] ) ) {
			$atts['title']	=	null;
		}

		// excerptパラメータが無かったらNULLにする
		if	(!isset($atts['excerpt'] ) ) {
			if			(isset($atts['content'] ) ) {
				$atts['excerpt']	=	$atts['content'];
			} elseif	(isset($atts['contents'] ) ) {
				$atts['excerpt']	=	$atts['contents'];
			} elseif	(isset($atts['description'] ) ) {
				$atts['excerpt']	=	$atts['description'];
			} else {
				$atts['excerpt']	=	null;
			}
		}

		// 囲まれ文字(ショートコード1のみ有効)
		if	($shortcode == $this->options['code1'] ) {
			switch	($this->options['use-inline'] ) {
			case	1:
				$atts['excerpt']	=	isset($content ) ? $content : null;
				break;
			case	2:
				$atts['title']		=	isset($content ) ? $content : null;
				break;
			}
		}

		// 記事内容取得
		$tag	=	$this->pz_GetHTML($atts );

		// 実行時間
		if	($this->options['debug-mode'] ) {
			if	(function_exists('hrtime' ) ) {
				$end_time		=	hrtime(true ) / 1000;
			} else {
				$end_time		=	microtime(true );
			}
			$elasped_time	=	$end_time - $start_time;
			$format_time	=	number_format($elasped_time / 1000, 8, '.', ',' );
			echo	'<!-- Pz-LkC [shortcode]'.PHP_EOL;
			echo	' URL='.$url.PHP_EOL;
			echo	' ElaspedTime='.$format_time.'ms'.PHP_EOL;
			echo	'-->'.PHP_EOL;
		}

		return	$tag;
	}

Code file location:

pz-linkcard/pz-linkcard/pz-linkcard.php

Conclusion

Now that you’ve learned how to embed the Pz-LinkCard 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 *