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.
- Contribution of external links to send visitors to the site.
- 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.
- Introduction to OpenGraph.php.
- Edit functions.php.
- Editing CSS.
- 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 readingCDN 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 readingCode Security Web Wordpress
How to prohibit access to wp-config.php.WordPress
Prohibiting access to wp-config.php improves site security. You are encouraged to refer to this information to maintain your website. Put the following code in the “.htaccess” file. <files wp-config.php> order allow,deny deny from all </files>
Continue readingCode Web Wordpress
How to save rewriting links.WordPress
If you are building multiple WordPress sites, you face the problem of having to ‘rewrite URLs’ when duplicating them. The following code is recommended to solve this problem before it happens. Please describe it in the theme’s ‘functions.php’ file. /*...
Continue readingPlant
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 readingCode 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 readingNews NGO
Non-governmental organization established.「DAIKICI NGO」
Today, the non-governmental organisation “DAIKICI NGO” was established. The aim is to grow and advance humanity while working to solve problems across the globe, whether local, national or international. There are many problems and challenges, but we want to work...
Continue readingCode 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 readingPlant
Copiapoa cinerea var. cinerea
Copiapoa cinerea is known as the ‘white cactus’ and is arguably the most popular cactus in Japan. Individuals with particularly white skin and pitch-black spines fetch high prices. 1. Synonym2. Origin3. Habitat4. Description5. Farming6. Way of increasing Synonym Below are...
Continue readingPlant
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