How to Create a Custom WordPress Widget

Do you want to create your own custom widgets in WordPress? Widgets allow you to drag and drop elements into any sidebar or widget ready area of your website. In this article, we will show you how to easily create a custom WordPress widget.

Creating a custom WordPress widget

What is a WordPress Widget?

WordPress widgets contain pieces of code that you can add to your website’s sidebars or widget ready areas. Think of them as modules that you can use to add different elements by using a simple drag and drop interface.

By default, WordPress comes with a standard set of widgets that you can use with any WordPress theme. See our beginner’s guide on how to add and use widgets in WordPress.

WordPress widgets

WordPress also allows developers to create their own custom widgets. Many WordPress themes and plugins come with their own custom widgets that you can add to your sidebars.

For example, you can add a contact form, a custom login form, or a photo gallery to a sidebar without writing any code.

Having said that, let’s see how to easily create your own custom widgets in WordPress.

Creating a Custom Widget in WordPress

Before we get started, it would be best if you create a site-specific plugin where you will be pasting the widget code from this tutorial.

You can also paste the code in your theme’s functions.php file. However, it will only be available when that particular theme is active.

In this tutorial, we will create a simple widget that just greets visitors. Take a look at this code and then paste it in your site-specific plugin to see it in action.

 // Register and load the widget
function wpb_load_widget() { register_widget( 'wpb_widget' );
}
add_action( 'widgets_init', 'wpb_load_widget' ); // Creating the widget class wpb_widget extends WP_Widget { function __construct() {
parent::__construct( // Base ID of your widget 'wpb_widget', // Widget name will appear in UI
__('WPBeginner Widget', 'wpb_widget_domain'), // Widget description
array( 'description' => __( 'Sample widget based on WPBeginner Tutorial', 'wpb_widget_domain' ), ) );
} // Creating widget front-end public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] ); // before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title']; // This is where you run the code and display the output
echo __( 'Hello, World!', 'wpb_widget_domain' );
echo $args['after_widget'];
} // Widget Backend public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'wpb_widget_domain' );
}
// Widget admin form
?>

After adding the code you need to head over to Appearance » Widgets page. You will notice the new WPBeginner Widget in the list of available widgets. You need to drag and drop this widget to a sidebar.

Custom WordPress widget added to a sidebar

Now you can visit your website to see it in action.

Previewing your custom widget

Now let’s study the code again.

First we registered the ‘wpb_widget’ and loaded our custom widget. After that we defined what that widget does, and how to display the widget back-end.

Lastly, we defined how to handle changes made to the widget.

Now there are a few things that you might want to ask. For example, what’s the purpose wpb_text_domain?

WordPress uses gettext to handle translation and localization. This wpb_text_domain and __e tells gettext to make a string available for translation. See how you can find translation ready WordPress themes.

If you are creating a custom widget for your theme, then you can replace wpb_text_domain with your theme’s text domain.

We hope this article helped you learn how to easily create a custom WordPress widget. You may also want to see our list of the most useful WordPress widgets for your site.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The Bizarre Quantum Test That Could Keep Your Data Secure

At the Ludwig-Maximilian University of Munich, the basement of physics building is linked to the economics building by almost half a mile’s worth of optical dietary fiber. It will take a photon three millionths of the second—and a physicist, about five minutes—to travel from one building to the other. Starting in November 2015, scientists beamed individual photons between the structures, again and again for seven months, for a physics experiment that could 1 day assistance secure your data.

Their immediate goal would be to settle a decades-old debate in quantum mechanics: perhaps the event called entanglement really exists. Entanglement, a cornerstone of quantum theory, describes a bizarre situation when the fate of two quantum particles—such as being a pair of atoms, or photons, or ions—are intertwined. You might split those two entangled particles to opposing sides of this galaxy, however when you wreak havoc on one, you instantaneously replace the other. Einstein famously doubted that entanglement had been actually a thing and dismissed it as “spooky action well away.”

Through the years, scientists have run a variety of complicated experiments to poke within theory. Entangled particles exist in nature, but they’re excessively delicate and hard to manipulate. So researchers make sure they are, often making use of lasers and special crystals, in precisely controlled settings to test your particles act the way in which prescribed by concept.

In Munich, researchers set about their test in two laboratories, one in physics building, others in economics. In each lab, they used lasers to coax an individual photon away from a rubidium atom; in accordance with quantum mechanics theory, colliding those two photons would entangle the rubidium atoms. That intended that they had to get the atoms both in departments to emit a photon basically simultaneously—accomplished by firing a tripwire electric sign from lab to another. “They’re synchronized to less than a nanosecond,” claims physicist Harald Weinfurter associated with the Ludwig-Maximilian University of Munich.

The researchers collided both photons by delivering one of these within the optical dietary fiber. They made it happen once again. And again, tens of thousands of times, followed up by statistical analysis. Even though the atoms had been separated with a quarter of the mile—along with the impinging buildings, roads, and trees—the researchers discovered the 2 particles’ properties were correlated. Entanglement exists.

So, quantum mechanics is not broken … which is precisely what the scientists anticipated. Actually, this experiment fundamentally shows the same results being a variety of similar tests that physicists started to run in 2015. They’re known as Bell tests, called for John Stewart Bell, the northern Irish physicist whoever theoretical work inspired them. Couple of physicists nevertheless question that entanglement exists. “we don’t think there’s any severe or large-scale concern that quantum mechanics will be proven wrong tomorrow,” states physicist David Kaiser of MIT, who had beenn’t involved in the research. “Quantum concept never, ever, ever let’s down.”

But despite their predictable results, scientists find Bell tests interesting for a many different explanation: they are often important to the procedure of future quantum technologies. “throughout testing this strange, deep feature of nature, people understood these Bell tests might be placed to get results,” says Kaiser.

Including, Google’s baby quantum computer, which it plans to test later this year, utilizes entangled particles to do computing tasks. Quantum computers could execute particular algorithms even more quickly because entangled particles holds and manipulate exponentially extra information than regular computer bits. But because entangled particles are incredibly hard to control, designers may use Bell tests to confirm their particles are in reality entangled. “It’s an elementary test that will show that your particular quantum logic gate works,” Weinfurter states.

Bell tests could also be beneficial in securing data, claims University of Toronto physicist Aephraim Steinberg, who had been perhaps not active in the research. Presently, scientists are developing cryptographic protocols predicated on entangled particles. To send a protected message to someone, you’d encrypt your message using a cryptographic key encoded in entangled quantum particles. Then you definitely deliver your meant receiver the key. “Every now and then, you stop and do a Bell test,” says Steinberg. In cases where a hacker attempts to intercept the important thing, or if the key had been faulty to start with, you will be able to view it within the Bell test’s data, and you also would know that your encrypted message is no longer secure.

Soon, Weinfurter’s team desires to use their test to produce a setup that could deliver entangled particles over long distances for cryptographic purposes. But at precisely the same time, they’ll keep performing Bell tests to prove—beyond any inkling of a doubt—that entanglement actually exists. Because what’s the purpose of developing applications along with an impression?

Get back to Top. Skip To: Begin of Article.

Why Governments Won’t Let Go of Secret Software Bugs

It’s been three days since WannaCry ransomware attacks began rippling across the world, affecting more than 200,000 people and 10,000 organizations in 150 countries. And the threat of further infection still looms.

The pervasiveness of WannaCry reveals just how insidious wide-scale ransomware attacks can be, endangering public infrastructure, commerce, and even human lives. But the implications of the incident don’t end there. The attack has transformed from an acute situation to be dealt with by security experts to a symbol of how fundamentally vital cybersecurity protection is and the true scale of what can happen when systems and devices lack crucial defenses. The far-reaching consequences of WannaCry has also revived a nuanced and longstanding debate about just how much risk the public should be exposed to when intelligence agencies secretly take advantage of vulnerabilities in consumer products.

Stockpiling Vulnerabilities

WannaCry’s evolution is the latest example. The attack spread by exploiting a Windows server vulnerability known as EternalBlue. The NSA discovered the bug and was holding on to it, but information about it and how to exploit it was stolen in a breach and then leaked to the public by a hacking group known as the Shadow Brokers. Microsoft issued a fix in mid-March, but many computers and servers never actually received the patch, leaving those systems open to attack. By holding on to this information instead of directly disclosing the vulnerability to manufacturers, this NSA espionage technique—ostensibly meant to protect people—caused a great deal of harm. And there’s no sign that groups like the NSA will discontinue this practice in the future.

“Even if what the NSA and the US government did is entirely right, it’s also okay for us to be outraged about this—we’re angry if a cop loses his gun and then it gets used in a felony,” says Jason Healey, a cyber conflict researcher at Columbia University, who studies the US government’s existing vulnerability and exploit disclosure process. “I think the government’s response to this is often ‘Look, this is espionage, it’s how the game is played, quit crying.’ And that’s just not cutting it. Everyone is right to be outraged and the government needs a better way of dealing with this.”

There’s certainly plenty of outrage that an NSA spy tool was stolen in the first place, then leaked, and then exploited to the detriment of individuals and businesses around the world.

“An equivalent scenario with conventional weapons would be the U.S. military having some of its Tomahawk missiles stolen,” Brad Smith, the president and chief legal officer of Microsoft, wrote on Sunday. “This attack provides yet another example of why the stockpiling of vulnerabilities by governments is such a problem. … We need governments to consider the damage to civilians that comes from hoarding these vulnerabilities and the use of these exploits.”

It is vitally important that tech companies release patches in an accessible way and that customers—both individuals and institutions—apply those patches. Experts agree that the tech community and its users share responsibility for the WannaCry fallout given that Microsoft had released a protective patch that wasn’t installed widely enough. But with intelligence agencies around the world essentially betting against this process, their decisions can have an outsized impact. Even Russian President Vladimir Putin invoked this reasoning while speaking in Beijing on Monday. “Genies let out of bottles like these, especially if they’ve been created by the secret services, can then harm even their own authors and creators,” he said.

Who Determines the Greater Good?

For its part, the US has been developing and implementing a program called the Vulnerabilities Equities Process since 2010. It requires intelligence agencies that obtain zero-day (i.e. previously unknown) vulnerabilities and/or exploits to disclose them within the government for review. The idea is to determine on a case-by-case basis whether a greater public good is served by keeping a particular vulnerability secret for espionage purposes or by disclosing it so the manufacturer can issue a patch and protect users at large.

So far the process has proved imperfect, and in fact, there is evidence that some agencies have been shielding bugs from oversight. “How do you reconcile [intelligence agencies’] stated need to use these tools and keep them secret with the fact that they keep leaking or being stolen and with the fact that they don’t seem to be accounting for that risk,” says Andrew Crocker, a staff attorney at the Electronic Frontier Foundation. “We need to have a reform of VEP or something like it where those risks are properly accounted for.”

Experts say that one possibility is to create a mechanism through which tech companies can participate in intelligence oversight when it comes to vulnerabilities in their products. Such an arrangement would be a major departure for spy groups used to extensive independence and secrecy, but companies that bear significant responsibility when spy tools leak could work as a check on agencies. “There just has to be balance,” says Stephen Wicker, a computer engineering professor at Cornell University who studies privacy and regulation. “The corporations themselves have to be involved in this line drawing somehow.”

There’s no reason to think that intelligence groups will stop seeking out and using undisclosed vulnerabilities and exploits, but WannaCry may serve as a more effective wakeup call for the intelligence community than past incidents simply because of its scale and impact on vital services likes hospitals. “Whether it results in changing anything on the inside, we the public don’t really have any way of knowing. There are mechanisms like Congressional oversight and reporting, but it’s all discretionary,” EFF’s Crocker says. “So I hope that’s an actionable thing that comes out of this—it does seem like everyone agrees that transparency and reporting and oversight and auditing of this area of the intelligence community is very much needed.”

And one concrete thing agencies can do to reduce incidental impact is devote even more resources and effort to securing their digital tools. Perfect security is impossible, but the more control intelligence groups can maintain, the less danger these spy tools pose.

“You cannot do modern espionage without these capabilities,” Columbia’s Healey says. “If you want to know what the Islamic State is doing if you want to keep track of loose nukes in central Asia, if you want to follow smugglers who are trying to sell plutonium, this is the core set of capabilities that you need to do that. [But] a minimum role of public policy is if you’re going to weaponize the IT made by US companies and depended on by citizens, for fuck’s sake at least keep it secret. If you’re going to have to do this, then don’t lose it.”

Go Back to Top. Skip To: Start of Article.

How to Display Author’s Twitter and Facebook on the Profile Page

Do you want to display your author’s Twitter and Facebook links on their WordPress profile page? By default, WordPress user profile page does not have any fields to add Facebook or Twitter profiles. In this article, we will show you how to easily display author’s Twitter and Facebook profile links in WordPress.

How to Add Author's Twitter & Facebook in WordPress Profile Page

1. Add Twitter and Facebook Profiles with Author Bio Box

This method is easier and is recommended for all users.

First, you need to install and activate the Author Bio Box plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit the Settings » Author Bio Box page in your WordPress admin to configure plugin settings.

Author bio box

First you need to select where you want to display the author bio box. The plugin can automatically show the author bio box below posts only or below posts and on homepage.

After that you can select background color, text color, gravatar size, border, etc.

Don’t forget to click on the save changes button to store your settings.

Next, you need to go to the Users » All Users page. Here you need to click on the edit link below the user account.

Edit author profile

This will bring you to the user’s profile page. You will notice that there are new social profile fields available on this page.

Now you just need to enter the author’s Facebook, Twitter, or any other social media profile URLs in the respective fields.

Enter your social profile URLs

Once you are done, click on the update profile link.

You can now view any posts written by that user, and you will see their author bio box with icons for their Twitter, Facebook, and other social media profiles.

Author bio box with social profiles

Registered users on your WordPress site can also edit their own profiles to add links for their Facebook and Twitter pages. You can also send an email to all registered users on your website and ask them to update their profiles.

2. Display Twitter and Facebook Profiles with Yoast SEO

This method is for advanced users because it will require you to edit WordPress theme files. If you haven’t done this before, then check out our guide on how to copy and paste code in WordPress.

If you are already using Yoast SEO plugin on your website, then you are in luck as it can be used to add Twitter and Facebook profile fields in author’s profile page.

The problem is that Yoast does not automatically display them in the author bio, but don’t worry we will show you how to do that.

Related: How to properly install and setup Yoast SEO plugin on your website.

Once you have Yoast plugin setup, you need to head over to the Users » All Users page, and then click on the edit link below the author name.

Edit author profile

On the user’s profile page, you will notice new Facebook and Twitter profile fields. For Twitter, you just need to enter the user handle without @ symbol.

For Facebook, you will need to enter the complete Facebook profile URL.

Facebook and Twitter fields in user profile

Once you are done, click on the update profile button to store your changes.

Now you need to display these fields as links in your theme.

You can do this by adding the following code to your theme files where you want to display the author profile links.

post_author );
$facebook = get_the_author_meta( 'facebook', $post->post_author );
echo 'Twitter | Facebook';
?> 

Save your changes and view a post on your website.

Here is how it looked on our demo website.

Author social profile links

We hope this article helped you learn how to display author’s Twitter and Facebook profile links in WordPress. You may also want to see our list of how to show an authors list with photos in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.