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.
	$blog_card .='
	<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 $blog_card;	
}

//Add to shortcode.
add_shortcode("blog_card", "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.

[blog_card 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.】

[blog_card 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.】

[blog_card 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.

Health

How to live longer.

1. Don’t Cigarette.2. Moderate exercise.3. Nutritious and balanced diet.4. Maintaining a healthy weight.5. Good quality sleep.6. Avoid stress.7. Conclusion. Don’t Cigarette. There are several best ways to live longer, but if asked to choose just one, ‘don’t smoke’, say researchers....

Continue reading

Arrival Shop

Accession in December 2024

More will appear in December! Pre-orders are also available.We hope you will order as soon as possible if you wish, as numbers are limited.

Continue reading

Code Web Without Plugin Woocommerce Wordpress

I want to assign ‘parent’ and ‘child’ to attributes in Woocommerce!How to enable without plug-ins.

Have you ever wished you could create ‘parents’ and ‘children’ for Woocommerce ‘attributes’, like categories? This function used to exist but has disappeared after version upgrades. To make it available in the current version, please add the following code to...

Continue reading

Plant Raise

The key points are sun, wind, water and soil! How to grow succulents.

Succulents are very easy to grow compared to other plants. There are four simple points. Maintain in a sunny location. Maintain in a well-ventilated area. Water when the soil is dry. Plant in well-drained soil. As long as the above...

Continue reading

Plant

Aztekium ritteri

1. Habitat2. Description3. Farming Habitat Usually grows on vertical limestone cliffs. It is endemic to two remote small areas in the Nuevo León region of north-eastern Mexico. It is endangered in its habitat due to illegal collection and natural erosion...

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

Plugin Security Web Wordpress

Change Table Prefix plugin for changing WordPress database prefixes (prefixes).

If you want to enhance the security of WordPress, you need to change the database table prefixes. If you want to make simple and quick changes after installation, this plugin is the one to choose. Change Table Prefix Light, fast...

Continue reading

Code Web Without Plugin Wordpress

Without Plugin!Easy copy and paste. how to add a site name shortcode to WordPress.

It is very time-consuming to rewrite site names when producing multiple sites. As a way of preventing this from happening, it is recommended to set up a system to call the name of the site by a shortcode. Write the...

Continue reading

Plant

Astrophytum asterias.

It is one of the cacti with the greatest number of persistent enthusiasts. Astrophytum asterias is particularly popular because of the large number of varieties and the ease of both hybridisation and seed production. The lack of thorns is considered...

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

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.