Without plugins!How to display a blog card with internal and external link support.|WordPress

Learn how to display blog cards in WordPress without using a plugin.

Plug-in non-use has various advantages, such as reducing server load and maintaining site display speed.

WordPress has a large variety of plugins, but you want to customise it without using as many as possible.

We would like to introduce an implementation method that we have also introduced on our website, in the hope that people of the same mind will find it useful.

Shortcode installation methods are available for internal and external links.

Completion image.

The following is a display image.

The design can be freely customised using CSS.

※If it does not appear, reload.

Internal link to a web page.

External links.

Objective.

Internal linking-enabled blog cards.

In the case of internal linking, “increasing the click rate of links to related pages across the site to increase the overall PV” is one of the methods of internal SEO for your own site.

Blog cards with external link support.

  1. Contribution of external links to send visitors to the site.
  2. Gaining some benefit from sending customers to external sites.

The acquisition of links from pages with relevant content is an SEO benefit for the externally linked site, which may return some benefit to your own site.

Installation method.

The following steps are required for installation.

  1. Introduction to OpenGraph.php.
  2. Edit functions.php.
  3. Editing CSS.
  4. Insert blog card with shortcode.

Installation of OpenGraph.php.

OpenGraph.php is a PHP file that allows various information to be retrieved from OGP tags on external sites.

File Download.

Download the file from the following website.

Click on the ‘Code’ button and download the complete set of files from ‘Download ZIP’.

Extracting and installing files.

Unzip the Zip file and place ‘OpenGraph.php’ in the same directory where functions.php is located.

Edit functions.php.

Edit functions.php.

If a child theme is available, use the child theme’s functions.php.

The instructions for each code are given at the top of each code for reference.

※Always make a backup before editing.

/* Create shortcodes for external link-enabled blog cards. */
function show_Linkcard($atts) {
	extract(shortcode_atts(array(
		'url'=>"",
		'title'=>"",
		'excerpt'=>""
	),$atts));
	
	//Specify the width of the image size.
	$img_width ="170";
	//Specify height of image size.
	$img_height = "170";
	
	//Get OGP information.
	require_once 'OpenGraph.php';
	$graph = OpenGraph::fetch($url);
	
	//Get the title from the OGP tag.
	$Link_title = $graph->title;
	if(!empty($title)){
		$Link_title = $title;//title=""If there is an input of the following, priority is given to that input.
	}
		
	//Get description from OGP tag (used as excerpt text).
	$Link_description = wp_trim_words($graph->description, 60, '…' );//Change the number of characters at will.
	if(!empty($excerpt)){
		$Link_description = $excerpt;//Manually when the value cannot be retrieved.excerpt=""Input.
	}
	
	//Get screenshots using wordpress.com API.
	$screenShot = 'https://s.wordpress.com/mshots/v1/'. urlencode(esc_url(rtrim( $url, '/' ))) .'?w='. $img_width .'&h='.$img_height.'';
	//Show screenshots.
	$xLink_img = '<img src="'. $screenShot .'" width="'. $img_width .'" />';
	
	//Favicon retrieval (scraping with Google's API).
	$host = parse_url($url)['host'];
	$searchFavcon = 'https://www.google.com/s2/favicons?domain='.$host;
	if($searchFavcon){
		$favicon = '<img class="favicon" src="'.$searchFavcon.'">';
	}
		
	//Blog card HTML output for external links.
	$sc_Linkcard .='
	<div class="blogcard ex">
	<a href="'. $url .'" target="_blank" rel="noopener noreferrer">
	 <div class="blogcard_thumbnail">'. $xLink_img .'</div>
	 <div class="blogcard_content">
	  <div class="blogcard_title">'. $Link_title .'</div>
	  <div class="blogcard_excerpt">'. $Link_description .'</div>
	  <div class="blogcard_link">'. $favicon .' '. $url .' </div>
	 </div>
	 <div class="clear"></div>
	</a>
	</div>';	
	
	return $sc_Linkcard;	
}

//Add to shortcode.
add_shortcode("sc_Linkcard", "show_Linkcard");

CSS code settings.

Finally, CSS adjustments are made.

The CSS code is shown below.

Copy and paste the whole thing into any style sheet, such as style.css.

.blogcard {
  line-height: 1;
  background-color: #fff;
  word-wrap: break-word;
  margin: 10px 0
}

.blogcard.ex {
  background-color: #f5f5f5;
  border-radius: 5px
}

.blogcard a {
  text-decoration: none;
  opacity: 1;
  transition: all .2s ease
}

.blogcard a:hover {
  opacity: .6
}

.blogcard_thumbnail {
  float: left;
  padding: 20px
}

.blogcard_title {
  font-size: 1em;
  font-weight: 700;
  line-height: 1.4;
  padding: 17px 20px 10px
}

.blogcard_excerpt {
  font-size: .85em;
  line-height: 1.6;
  padding: 0 17px 15px 20px
}

.blogcard_link {
  font-size: .9em;
  padding: 0 17px 15px 20px;
  text-align: left
}

.blogcard_link .favicon {
  margin-bottom: -4px;
  width: 18px;
  height: 18px
}

The design can be changed to any desired design by customising the CSS.

CSS for smartphones.

CSS code to support smartphone display.

@media screen and (max-width:768px) {
  .blogcard {
    margin: 10px 0
  }
  .blogcard_thumbnail img {
    width: 90px
  }
  .blogcard_title {
    font-size: .95em;
    padding-bottom: 17px
  }
  .blogcard_excerpt {
    display: none
  }
}

When you have finished editing the CSS, save it to the CSS used by your theme.

This completes the set-up.

How to display your blog card.

Insert the following short code.

[sc_Linkcard url="Link to URL"]

For example, if you want to display the card ‘https://x.com/’, the shortcode would be as follows.

【Short code examples.】

[sc_Linkcard url="https://x.com/"]

【Representation example.】

If the title or description of the external link cannot be obtained, or if you want to include individual wording, it is possible to manually enter “title” and “excerpt” in addition to “url” in the shortcode to display any text.

【Short code examples.】

[sc_Linkcard url="https://x.com/" title="Arbitrary title name." excerpt="Optional explanatory text."]

【Expression Example.】

Conclusion.

In this article, we showed you how to display internal and external link-supported blog cards in WordPress without using a plugin.

The work itself does not take long and can be implemented quickly, so please refer to this if you like.

We are also planning to add conditional branching and introduce methods to reflect only certain article pages and not affect other page speeds, so we hope you will continue to subscribe to our newsletter.

Thank you for watching until the end.

CDN Security Speed

DNS configuration with Cloudflare.Set up bombastic DNS for a more comfortable IT life.

DNS configuration with Cloudflare not only speeds up browser start-up, but also contributes to improved security. Please give it a try. 1. 1.1.1.12. ​​1.1.1.1 family oriented.2.1. ​​Blocks malware.2.2. ​​Blocks malware and adult content. 1.1.1.1 1.1.1.1 is Cloudflare’s public DNS resolver.It...

Continue reading

Code Web Without Plugin Woocommerce Wordpress

Without Plugin!How to display just any item on the Woocommerce My Account page.

The items on the Woocommerce My Account page vary depending on the products handled and the site they are on. For example, if you want to hide the ‘Dashboard’ and ‘Downloads’ items, you can achieve this by doing the following....

Continue reading

Sponsor

Frecer Sponsorship applications are now open!

We are pleased to announce that we are now accepting applications for Frecer sponsorship. Sponsor We offer a variety of plans and special offers. The funds you support will help to realise a number of projects. We sincerely look forward...

Continue reading

Code Web Without Plugin

CSS when long links overhang.You can also take measures on your mobile phone!

When viewed on a smartphone, long links may protrude horizontally.If this is the case, the following styles can be used to deal with the situation. a{word-break: break-all;}

Continue reading

Code Speed Web Without Plugin Wordpress

Without plugins!How to use syntax highlighting Prism.js.|WordPress

In this article, we will show you how to implement syntax highlighting in WordPress without using a plugin. Syntax highlighting is often used to display source code on websites and blog sites. This website has adopted “Prism.js” after various trials....

Continue reading

Plant

Agave victoriae-reginae ‘Sasanoyuki’

1. Basic Information.1.1. Scientific name1.2. Family name1.3. Genus name1.4. Species name1.5. Country of origin1.6. Habitat1.7. Morphology1.8. Mature tree1.9. Cold hardy1.10. Heat tolerant1.11. Sunshine1.12. Flour color1.13. Flowering period Basic Information. Scientific name Agave victoria-regina Family name Asparagaceae Genus name Agave Species...

Continue reading

Plant

What is Gymnocalycium vatteri?

Gymnocalycium vatteri is a cactus of the genus Gymnocalycium. Native to Argentina-Uruguay in South America, it is rich in varieties and delights horticultural enthusiasts. All of these are seedlings with a tangle of local globe seedlings. It was kept in...

Continue reading

Code Security Web Wordpress

How to make all pages permanently SSL.WordPress

Has SSL been installed on your website? The introduction of SSL is recommended for all websites because of its security and SEO advantages. Full-page SSL is particularly desirable for shopping and crowdfunding websites where personal data and payments are involved....

Continue reading

Code

How to unzip a zip file in the server.

Assume the file you want to unzip is ‘example.zip’. 1. 1:Upload the zip file you want to unzip.2. 2:Creating and uploading unzip.php.3. 2:Access unzip.php.4. 3:Deployment of zip.5. 4:Finish. 1:Upload the zip file you want to unzip. Upload the zip file...

Continue reading

Speed Web Wordpress

How to optimise page speed in WordPress.WordPress

If a web page does not load within the first two seconds, 55% of mobile users will leave that web page. Furthermore, around 70% of consumers in online stores report that page display speed is linked to their willingness to...

Continue reading

Leave a Reply

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.