WordPress Questions Flashcards

1
Q

What is the latest version of WordPress (as of 6.25.24) and what are some of the major features?

A

6.5.5 - Addressed some cross-site scripting (XSS) vulnerabilities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the WordPress Loop?

A

The WordPress Loop is a php code used to display posts. It processes each post to be displayed on the current page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create a child theme in WordPress?

A

Create a new folder in the “/wp-content/themes/” directory, add a style.css file with the meta comments/theme header and import the parent theme’s stylesheet and optionally add a function.php file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the function of “wp_enqueue_script()’

A

It safely adds Javascript files to your WordPress site, and you can combine it with other functions to intelligently load your script only on pages where your shortcode is present by using a global flag variable in your shortcode output function (set default to false), then hook your enqueue function in ‘wp_enqueue_scripts’ and conditionally enqueue based on your global variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you add custom post types in WordPress?

A

Use the “register_post_type()” function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of hooks in WordPress?

A

Hooks allow developers to add their own code into WordPress’ core functionality without modifying core files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between actions and filters?

A

Actions allow you to add or modify functionality at certain points during the execution of WordPress.

Filters allow you to modify data that is sent back/forth to the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you create a custom WordPress Plugin?

A

Create a new PHP file in the “wp-content/plugins” directory, add a plugin header, and then write your code!

<?php
/*
Plugin Name: My First Plugin
Description: This is my first plugin! It makes a new admin menu link!
Author: Your Name
*/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the function of “add_theme_support()”

A

It enables various theme features such as post thumbnails, custom headers, and backgrounds.

If attached to a hook, it must be ‘after_setup_theme’. The ‘init’ hook may be too late for some features.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can you secure your WordPress site?

A

Keep themes, plugins, and core up-to-date
Rewrite or move the wp-login.php page
Setup 2FA
Strong password policy and forced resets every 3-6 months
Regular backups
IP restrict “/wp-content/” directory (make exceptions for login/out)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the REST API in WordPress?

A

The REST API provides a way to interact with WordPress from outside the WordPress installation, allowing developers to send and receive data as JSON - this is a requirement for headless WordPress installations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you debug in WordPress?

A

Set the “WP_DEBUG” environment variable to “true” in ‘wp-config,’ or you can monitor the log file (debug.log) if on the production site.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is ‘wp_head()’ used for?

A

It is a template tag used to insert elements in the ‘<head>’ section of a WordPress site.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you create a custom taxonomy?

A

Use the ‘register_taxonomy()’ function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are WordPress template hierarchy and its importance?

A

It determines which template file WordPress uses for each page. It allows for customization and flexibility in theme development.

Examples:
index.php
home.php
front-page.php
page.php
page-{slug}.php – If the page slug is privacy, WordPress will look to use page-privacy.php.
page-{id}.php – If the page ID is 6, WordPress will look to use page-6.php.
single.php

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can you optimize WordPress performance?

A

Use caching, asset delivery optimization, image compression and lazy loading, use a CDN, and keep the database optimized.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Explain the role of ‘functions.php’ in WordPress.

A

Functions.php is a boilerplate file within your theme and can be used to add features and functionality to your WordPress site.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the purpose of ‘wp_reset_postdata()’?

A

It resets the global $post object to the current post in the main query after a custom query has been run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How doy ou change the URL structure in WordPress?

A

By modifying the permalink settings in the WordPress admin under settings > permalinks. Or can be modified further by utilizing the “Custom Permalinks” plugin.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is your preferred plugin for SEO?

A

Yoast Premium is the industry standard in many cases, but my favorite is SmartCrawl by WPMUDev. They have an incredible feature that allows you to auto-insert links into pages based on keywords.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the difference between “get_template_directory()” and “get_stylesheet_directory()”?

A

“get_template_directory()” returns the path to the parent theme directory, while “get _stylesheet_directory()” returns the path to the current/active theme directory (child or parent).

22
Q

How do you add a widget area to your WordPress theme?

A

Use the “register_sidebar()’ function, and then use “dynamic_sidebar()” to display it.

23
Q

What are shortcodes and how do you create one?

A

Shortcodes are small code snippets that allow you to add dynamic content to your posts and pages. You can create one using the “add_shortcode()” function.

24
Q

What is a multisite in WordPress?

A

A multisite is a feature that allows you to create a network of sites (multiple DB installs) that use a single WordPress installation.

25
Q

How can you change the default login URL?

A

Use a plugin like WPS Hide Login or modify the .htaccess file.

RewriteRule ^admin$ /wp-login.php [NC,L]
RewriteRule ^admin/(.*) wp-admin/$1?%{QUERY_STRING} [L]

26
Q

What is the function of “get_post_meta()”?

A

Retrieves the value of a custom field (post meta) for a post.

27
Q

How do you make a WordPress site multilingual?

A

Use plugins like WPML or Polylang to add multilingual support.

28
Q

How can you disable the WordPress admin bar?

A

Use the “show_admin_bar(false)” function

29
Q

What is the purpose of the .htaccess file in WordPress?

A

It is used to control the configuration of the Apache web server, including permalink structure, redirects, and security settings.

30
Q

How do you customize the WordPress login page?

A

Add custom code to “functions.php” to enqueue custom styles (for minimal style changes) or use plugins like LoginPress, Forminator, WPForms to overhaul the form.

**To enqueue styles specifically for the wp-login.php page in WordPress, you can use the “login_enqueue_scripts” action hook.

31
Q

What is the use of “get_option()” and “update_option()” functions?

A

“get_option” retrieves a value from the WordPress options table, and “update_option” updates or adds a value to the options table.

32
Q

How do you create a custom WordPress query?

A

Use the WP_Query class to create custom queries.

<?php

// The Query
$query1 = new WP_Query( $args );

// The Loop
while ( $query1->have_posts() ) {
$query1->the_post();
echo ‘<li>’ . get_the_title() . ‘</li>’;
}

/* Restore original Post Data
* NB: Because we are using new WP_Query we aren’t stomping on the
* original $wp_query and it does not need to be reset with
* wp_reset_query(). We just need to set the post data back up with
* wp_reset_postdata().
*/
wp_reset_postdata();
?>

33
Q

What does the “wp_reset_query()” function do?

A

It resets the query used with custom loops.

34
Q

What are WordPress transients and their use?

A

Transients are a way to store cached data with an expiration time. They help improve performance by reducing the number of database queries. Their primary use cases are to store session data, prevent the need for repetitive + expensive DB queries, as well as caching API requests.

1 – How to Create a Transient:
$api_response = wp_remote_get(‘https://api.example.com/data’);
$data = wp_remote_retrieve_body($api_response);

// Store the data for 12 hours (43200 seconds)
set_transient(‘example_api_data’, $data, 43200);

2 – Retrieve a Transient:
$data = get_transient(‘example_api_data’);

if (false === $data) {
// Transient expired or does not exist
// Fetch the data again and set the transient
$api_response = wp_remote_get(‘https://api.example.com/data’);
$data = wp_remote_retrieve_body($api_response);
set_transient(‘example_api_data’, $data, 43200);
}

3 – Delete a Transient
delete_transient(‘example_api_data’);

35
Q

How do you migrate a WordPress site?

A

Download files and DB dump, upload to new server, search/replace DB if changing domain, import DB to new server, update wp-config with new DB credentials, upload site files, move the A record for the DNS. boom.

36
Q

Explain the concept of template parts in WordPress?

A

Template parts allow you to modularize your theme by creating reusable pieces of template code such as headers, footers, and sidebars.

37
Q

How do you add theme options in WordPress

A

You can use the WordPress Customizer API to add theme options that can be managed through the WordPress admin area. However, I prefer to use plugins like Advanced Custom Fields, which also comes packaged with admin menu page builder functions for quick backend customization.

38
Q

What is the difference between “include()” and “require()” in PHP?

A

“include()” will emit a warning and continue if the file is not found, whereas “require()” will produce a fatal error and stop execution.

39
Q

How do you implement pagination in a custom WordPress query?

A

Use “paginate_links()” or “the_posts_pagination()” functions.

40
Q

How can you protect your WordPress site against SQL injections?

A

Use prepared statements with the “$wpdb” class and sanitize user input.

41
Q

What is the purpose of “wp_nav_menu()”?

A

It is used to display a custom navigation menu in WordPress.

42
Q

How do you register and enqueue stylesheets in WordPress?

A

Use “wp_register_style” and “wp_enqueue_style”

43
Q

What are custom fields in WordPress?

A

Custom fields are additional metadata that can be added to posts, pages, or custom post types.

44
Q

How can you optimize a WordPress database?

A

Use plugins like WP-Optimize or manually run SQL commands to bloat from the DB such as post revisions, logs, etc.

45
Q

How do you create a custom 404 error page in WordPress?

A

Create a “404.php” file in your theme directory.

46
Q

How can you prevent comment spam in WordPress?

A

First, you can disable comments sitewide (Settings > Discussion > Default Article Settings) - most sites don’t need comments.

For those that DO need comments. I would use plugins like Akismet to enable CAPTCHA.

47
Q

What is the purpose of “wp-config.php”?

A

It contains the configuration settings for your WordPress installation, including DB credential, multisite configuration, and debugging settings.

examples:
define(‘WP_LOG’, true);
define(‘WP_DEBUG’, true);
define(“SCRIPT_DEBUG”, true);
define( ‘WP_ALLOW_MULTISITE’, true );

48
Q

How do you use “wp_nonce_field()” and “check_admin_referer()”?

A

“wp_nonce_field()” generates a nonce field for security, and “check_admin_referer()” verifies the nonce to prevent CSRF attacks.

49
Q

How can you enable debugging for Javascript in WordPress?

A

Use the “SCRIPT_DEBUG” constant in the “wp-config.php” file and use browser developer tools like inspector to crawl the DOM.

50
Q

What is the difference between “get_posts()” and “WP_Query”?

A

get_posts() is a simpler way to retrieve posts with less flexibility. WP_Query is more flexible. You can even use $wpdb to run pure SQL queries.