Wordpress 2 Flashcards

1
Q

Wordpress uses a ……… templating system?

A

distributed

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

What principle is the templating system in wordpress based on?

A

DRY - Don’t Repeat Yourself.

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

What is one of the most important things you have to do in the functions.php to allow support of child themes?

A

You should wrap your functions in a conditional block:

if ( ! function_exists('the_name_of_function')) {
   function the_name_of_function() {
   }
}

This allows child theme creators to override your functions if they need to. This is referred to as “pluggable functions.”

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

Under appearance in the WP dashboard, there are some sub menus, like “themes”, “header” etc. Where are these defined?

A

In functions.php. There are entries for “add_theme_support” that allow you to add / remove options from the menu list.

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

The call to add extra stylesheets should always be done where?

A

In the head section of the markup - however, you don’t add these directly, you must use the enqueue function from functions.php

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

In the styles.css file there is a section called css reset - should you touch this?

A

No, in general leave it as is.

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

Why is it useful to use rem’s to resize fonts?

A

The rem (or relative em size) is based on the outer most element (the body tag) - in underscores for instance, this will be set to 100%, so when using rem’s you can be sure you are using a consistent sizing method, and you shouldn’t get screwed by hierarchical nonsense.

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

Not every browser supports rem sizing, how do you support a fallback?

A

Make sure you put both px and rem size, and make sure the rem size comes after the px size. That way, if rem isn’t supported it’s simply ignored, and if rem IS supported, it will overwrite the px size.

font-size: 16px;
font-size: 16rem;

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

How do you use hsl colors in your css?

A

color: #404040;
color: hsl(0, 0%, 25%);

NOTE: First 0 doesn’t have a percentage, and note that we are providing a fallback for browsers that don’t support it.

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

If you want different styles to apply to different pages, where should you put your css?

A

It should likely go into one of the css files (content-sidebar or sidebar-content) in the layouts folder. In order to load this, you need to enqueue it in the functions file.

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

What are the three main elements that are typically kept in the header.php file?

A

The site title, the site tagline and the main menu

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

The enqueue scripts are hooked into what function?

A

wp_head();

This means that all the styles, scripts etc that you enqueue in functions.php, will appear in the header at the location of the wp_head() call.

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

What is the custom header feature in wordpress?

A

It is a feature that allows the user to modify how the header is display. It must be enabled in wordpress, usually through the functions.php file (some themes may wrap the functions in a file in the inc directory).

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

What is one of the gotchas with using the custom header function?

A

There is an option (tick box) that allows you to disable the display of the site text. However, this means the HTML may still be showing in the header.php file.

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

When you setup a theme so that you can edit the theme in the customizer, where does the config occur?

A

In a js file called customizer.js (at least for the underscores theme it is).

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

If you make a change in customizer.js and it doesn’t change in the customizer, what may be the problem?

A

A lot of browsers will cache customizer.js, you must flush the cache in the browser.

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

What is the best tool for enabling keyboard control of menus?

A

Super Fish

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

How do you add a custom search form?

A

In the header, you can simply call get_search_form() and wordpress will give you the html for the form. You can add additional styling by wrapping the form in your own HTML.

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

If you are using something like font-awesome, it uses i tags to inject an icon/font into a page using CSS. What does this mean for accessibility?

A

If you are using a keyboard or screenreader, you will not be able to access the icon as it technically doesn’t exist. You should use a anchor link (a href) to make sure there is something for it to find. You can use the css (wordpress) class screen-reader-text to hide it so it doesn’t affect layout.

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

What css class can be used to hide an item and what is the caveat?

A

screen-reader-text

However, this is intended for items that should be invisible to a user, but visible to screen readers or keyboard input for accessibility purposes. Therefore you shouldn’t just use it on everything.

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

Wordpress refers to the location that widgets can go as the “sidebar” - is that technically the only place they can go?

A

No - that is legacy. Widgets can also go in the footer, or elsewhere on the page.

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

Where are widgetised areas created?

A

functions.php

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

What function is used to create a widgetised area?

A

register_sidebar()

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

What html element are widgets usually wrapped in?

A

An “aside” tag

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

What function is responsible for actually displaying the sidebar widget area?

A

dynamic_sidebar

You use this in sidebar.php, and test whether there is a dynamic side bar (this will be the name you defined in functions.php). If there isn’t one, you should output some basic default widgets instead.

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

What function is responsible for actually using the sidebar template?

A

get_sidebar(), which you would use in the other template files.

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

There is a default sidebar template called sidebar.php - and you call that with get_sidebar(). How would you call a custom sidebar template for a footer?

A

If you have called the sidebar file “sidebar-footer.php”, then you can call it from any template file with the following function:

get_sidebar(‘footer’);

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

What function can you use to test if there are widgets in the sidebar currently?

A

is_active_sidebar(‘sidebar-2’)

NOTE: You will want to use this in say, a footer. It allows you to do a conditional test, then bail out of the template, rather than printing the surrounding widget formatting area (which is fine in a traditional sidebar).

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

Masonry is a javascript script that tiles block elements nicely - how do you enable it in Wordpress?

A

You enqueue it in functions.php using the standard enqueuing process. By passing the array(‘masonry’) parameter in the enqueue function, you will tell it to load that inbuilt javascript.

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

How do you create a comments link in a post page, and make it so that it is contextual to none, 1 or more comments being present?

A

comments_popup_link(__(‘Leave a comment’, ‘my-simone’), __(‘1 Comment’, ‘my-simone’), __(‘% Comments’, ‘my-simone’));

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

If you call the comments_popup_link function on a page, but no comments show up, why might that be?

A

Comments could be disabled for the post.

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

When styling a list or a string where you want characters to appear only at certain screen sizes, how can you achieve this?

A

You can use CSS pseudo selectors

@media screen and (max-width: 1319px){
    .posted-on:before {
        content: ' on ';
    }
    .posted-on:after {
        content: '.';
    }
}

This would mean something likes like “January 15th”, would end up looking like “ on January 15th. “

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

What is one “odd” feature of using pseudo selectors to add content into an element?

A

You can’t use your mouse to select it, since it’s not actually in the HTML.

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

What are block quotes?

A

They are a HTML tag that makes the encapsulated text stand our from the surrounding content. It’s the same thing as in printed media when you get an excerpt of text floating within the column, quoting an important piece.

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

What is “Pull content”?

A

It’s basically block quotes that have been slightly pulled out of the flow, so that it stands out.

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

What built in wordpress class allows blocks to be left and right alligned?

A

alignright

alignleft

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

How can you change how many top level comments are displayed in a wordpress post?

A

In the admin screen, go to discussions. Then change the “break comments into pages with … x”
Here you can set the number of top level comments per page.

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

How are comments output?

A

If you look in the single.php, you will find a call to comments_template(), which calls the template file. This will normally be comments.php

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

What function ACTUALLY displays each comment?

A

wp_list_comments

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

What function displays the comments form that you can enter your comment into?

A

comment_form()

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

How do you change the default size of a gravatar image in the comments?

A

When you call wp_list_comments, pass an additional parameter:

‘avatar_size’ => 50

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

How do you hide gravatar images through code?

A

When you call wp_list_comments, pass an additional parameter:

‘avatar_size’ => 0

NOTE: By setting it to zero, WP will not make a call to gravatar, and the icons will not be displayed.

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

What do you have to take into consideration when styling comment forms?

A

There are two versions - one when you are logged in, and when you are just a visitor.

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

What can you do to reduce the amount of work you have to do when styling a comment form?

A

Just style the public version (i.e. not logged in version) - the logged in version will inherit those styles and capture most if not all of the possible requirements.

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

What considerations do you need to take into account when styling errors for comment forms?

A

Some errors only appear based on settings in wp-admin. Which means you’ll have to toggle them to test.

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

What class wraps the waiting for moderation error message?

A

content-awaiting-moderation

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

What were “featured images” previously called?

A

Post thumbnails

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

All of the images, text, titles etc of a post is stored in how many fields?

A

A single field - and is retrieved by “the_content()”.

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

Is the featured image contained within the same data as the main post?

A

No, it is separated, so that when building an index or front page, you don’t have to retrieve the entire post to just put the featured image up.

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

How to retrieve the featured image?

A

the_post_thumbnail()

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

If all the data for a single post is in one field, how would you get just a small portion of the article for a front page link?

A

the_excerpt()

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

Is it possible to define multiple thumbnail sizes (i.e. one on the front page, and one on the main post?)?

A

Yes - you can pass the defined name of the image to “the_post_thumbnail()”

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

How do you define what size of “featured images” are avilable to your theme?

A

You must have enabled post-thumbnails support to wordpress first.

Then use the function add_image_size

add_image_size(‘name’, width, height, crop);

(in functions.php)

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

If you use add_image_size and set the crop parameter to true, how does wordpress crop it?

A

It will scale the width to match the width, and then crop the height.

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

If you use add_image_size and set the crop parameter to false, how does wordpress crop it?

A

If the image is larger than the specified size, it will draw the image at the specified size (potentially stretching / squashing it).

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

How would you allow someone to upload an image that is basically any height?

A

If you set add_image_size with the following parameters:

add_image_size(‘name’, 780, 9999, true);

Then wordpress will make the image the appropriate width, but if the image is smaller than 9999 (which it should be) it will not crop it. This will allow someone to upload really tall images if required.

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

If you have used the downloadable test data - but only just changed the image size attributes for your theme, what can you do about the existing images that wont’ have thumbnails?

A

In the developer tools plugin, there is a tool called “regenerate thumbnails” - simply run this and it will create thumbnails based on the sizes specified in functions.php

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

Because “the_post_thumbnail” only returns the image code, what do you have to take into consideration with regards to wrapping it in a div for formatting?

A

If there is no image, then you should not output the div. You can test this using “has_post_thumbnail()”.

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

What are the main three ways we can display the content on an index page?

A

An excerpt, the first 55 words, or the full content.

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

How can the user define where to put the “read more” link if the full content is displayed on an index page?

A

By inserting the more tag within the content. This is via a button in the WYSIWYG editor in WP.

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

How do you customise the wording of the more tag?

A

Switch to text view in the editor, and find the more tag (which is just a comment with a more at the begining). Then change the text after the more tag.

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

When we create an excerpt, we should add a link to the bottom of the shortened text to allow a user to “read more”. What rel (relation) should this link be?

A

bookmark - because technically, this is a book mark.

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

What function can be used to create a navigation element that displays page numbers?

A

paginate_links

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

What function can you use to determine whether a post is “sticky”?

A

is_sticky

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

If you wanted to support the aside post format, and use a custom template to display it, what would you call the template?

A

content-aside.php

Which would be called from the index based on the function call:
get_template_part(‘content’, get_post_format());

Because the user has set the post as an “aside” where you call get_post_format, will be the word “aside”. Combined with the first parameter - “content-aside.php”.

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

What is an “aside” in wordpress?

A

It’s like a short blog post - generally doesn’t have a title, or a “read more” link. It would normally be read from the index page.

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

Can you create a new or custom post formats?

A

No - there are only the default ones. You can customise how the pages display using templates (content-[post format name].php).

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

What function can you use to determine whether the post you are reading is on the front page or in an archive?

A

is_font_page()

Test for this to determine if it is on the front page.

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

What function can you use to determine if the post you are reading is on the first or subsequent pages?

A

is_paged()

This will tell you if the posts are paged (i.e. on page 2 +)

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

What conditional statement could you use to get the first post, and only the first post (i.e. on a front page) so you can format it differently to the rest of the posts?

A

if ($wp_query->current_post == 0 &&
!is_paged() &&
is_front_page()) {

     // Setup styles here.
}

We are saying, if it’s the first item in the query result, and it’s not on a page (i.e. page 2 or more), and it’s a front page post (i.e. not an archive) - then bam.

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

What function can you use to get the title of a category archive?

A

single_cat_title()

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

What commonly requested custom page template is a good idea to include in your themes?

A

A no side bar custom page. Basically all the content aligned to the middle.

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

Why is it a good idea to separate your layout css styles into another file?

A

So when you are creating a custom page template, you can setup specific layout css - and it wont be interfered with by other styles.

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

How would you make an option for a template with the name “Page with no sidebar” appear in your page editor?

A

If you create a file called page-nosidebar.php (note - it doesn’t seem to matter that the page- prefix is there).

Then in the header, create a comment that has the following text:

/**
* Template Name: Page with no sidebar
*/
The option will appear in your page editor.

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

If you have created a new css file, for the purposes of laying out a custom page template, how do you make that css file load only for that page?

A

using is_page_template, you can pass it the name of the page template - if it matches, then enqueue the specific css file.

if (is_page_template(‘page-templates/page-nosidebar.php’)) {
wp_enqueue_style(‘my-sinome-layout-style’, get_template_directory_uri() . ‘/layouts/no-sidebar.css’);
}

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

Why is it a good idea to add custom styles to the editor?

A

So that when a user is editing a page, the editor accurately reflects what will be seen on the front page - the editor uses by default, the internal wp styles.

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

What function can be used to use tell the editor to load a specific css file for the editor?

A

add_editor_style

78
Q

Why should you never use template-blog.php for displaying blogs?

A

If the “static front page” feature configuration in the “reading” section of “settings” is setup correctly, wordpress will never use the template. It only uses home.php and index.php (in the hiearchy).

79
Q

If the “reading settings” are set to “latest posts”, which page is used to display the blog?

A

page.php

80
Q

If the “reading settings” are set to “a static page”, which page is used to display the blog?

A

Assuming the pages are configured correctly, and a page named “blog” or “news” has been created, then the “home.php” or “index.php” files will be used. No others.

81
Q

If the “reading settings” are set to “a static page”, which page is used to display the static front page?

A

Assuming the pages are configured correctly, and a page named for instance “home” is set as the front page, then front-page.php will be used (or the custom template that was selected for the page).

82
Q

If you have a front-page.php file and a page-mytemplate.php file, and you set the front page to use “mytemplate”, why is front-page still used?

A

Because it’s higher in the hierarchy. Because front-page exists it will never get to “mytemplate”.

83
Q

Where is the debug bar displayed from?

A

get_footer()

84
Q

get_header() calls the file “header.php”, how would you get it to call a custom header?

A

You can have a different header for different parts of the site (use an if statement and check for things like “is_home()”) - you simply call get_header(‘home’);

There should be a corresponding file called header-home.php to implement that header.

85
Q

What does the function is_home() check for?

A

If the page is in the blog post index context, the function is_home() will return true.

This is different to is_front_page() which will return true if we are in the site front page.

NOTE: These two things can occur at the same time! For instance, if you using a static front page and and “show_on_front” is set to true, then both is_front_page() and is_home() will be true.

86
Q

It would be possible to add arrows to expanding menus in Wordpress using just CSS3. But this is hard to support for IE8 and earlier. What is another option?

A

The wordpress function wp_nav_menu populates menu items with a class called “page_item_has_children”. This can be used to target the menu items to add arrows. It does not require an special css.

87
Q

You try loading a font-face via wp_enqueue_* and you get an error saying “Unexpected token ILLEGAL”. The error points to the first line of your CSS which happens to be an @font-face call. What is the error?

A

You are probably trying to load the CSS with a wp_enqueue_script call. It has to be wp_enqeue_style.

88
Q

You’ve setup a glyph font, like font-awesome or genericons - and they don’t fucking work. Everything looks okay, what could be the issue?

A

Check that the last parameter in wp_enqueue_style is set correctly. It takes a string or a boolean. The problem is if it is set to true it seems to prevent the CSS from loading properly for most pages. It is intended to take a media type (i.e. “screen, all” etc). And it would appear that passing a value of true makes it invalid for most screen types.

89
Q

You are trying to remove the default gradient off of a button element, it’s not working. What should you try?

A

box-shadow: none;

90
Q

What is the issue with having an absolutely positioned menu, that you wish to extend below the container?

A

Firstly, it will likely expand within the container. But even if you can get it to expand below, because it is “absolute” positioning, it will not push the content below it down, rather covering it up.

91
Q

The customizer is object oriented, what is the basic hiearchy of elements in the customizer?

A

Panel
Section
Setting
Control

92
Q

What class is responsible for booting the theme customiser on the server side?

A

WP_Customize_Manager

93
Q

There are two primary types of settings in the customizer, what are they?

A

Options and theme modifications.

NOTE: Options are site wide, and generally should not be modified or created by a theme. The theme modifications on the otherhand are fine.

94
Q

Where are the options settings stored?

A

in the wp_options table - in general options should not be added to by a theme, as they are site wide, not theme based.

95
Q

In the WP_Customize_Manager class, there is a add_setting method. It takes an array as a parameter, and one of the options is “type”. What are the two different values it can take?

A

theme_mod and option

Generally “theme_mod” is the value it should have as options should not be modified by a user theme.

96
Q

How could a custom CSS plugin ensure that the CSS is not lost each time the theme is switched and switched back again?

A

You could register the custom theme css setting with the WP_Customize_Manager as a “theme_mod”. This way each theme can have it’s own, and when you switch between themes, it will remember the last setting.

97
Q

What is the most important aspect of creating a new setting using WP_Customize_Manager?

A

You should always set a default value so that no unsafe data is stored in the database.

98
Q

What function do you use to add a menu to the admin area?

A

add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);

99
Q

In the following function, what does the $capability parameter describe?

add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);

A

It’s a string that represents the user’s role that is alowed to see the menu. I.e. Administrator, Author etc. This is tied into Wordpress’s user role system.

100
Q

Which parameters are mandatory in the following function?

add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);

A

The first 4, although you’ll probably want to control $function too as the results without it are a little confusing. $function is the callback that will render the page.

101
Q

Is a post just a blog post?

A

No, it’s basically any content within wordpress, a product, a blog post a page. All posts.

102
Q

You’ve just installed wordpress, you change your permalink structure to “post name” - and then you realise your 404 pages are not working, what could be the problem?

A

If the root directory permissions are incorrect, then the .htaccess file may not get written. This has the side effect of apache not being able to determine the correct 404 page, and it uses it’s own error message. No matter what you do, you will not fix this until the permissions are fixed, at which point it will use the 404.php page, or index (based on the template hierarchy).

103
Q

Does the wp_footer() function call belong in the footer markup?

A

No, in fact wp_footer should be outside of all markup, just BEFORE the final body tag.

104
Q

Why is the body_class function so useful?

A

WP will add a buncy of classes to the body tag in your html (assuming you have called body_class in that tag) - and it gives you information such as whether you are logged in, if customisation support is provided, what page you are on etc.

105
Q

The body_class function provides some useful information (classes for styling) for the entire page, what is another function that does a similar job for a post entry?

A

post_class();

106
Q

What does trailingslashit() function do?

A

Removes a trailing slash before adding it - this prevents duplication of a trailing slash.

107
Q

Why does “the_date()” sometimes not work in Wordpress?

A

Because it will not display the date for two posts on the same day. This is actually expected behaviour.

108
Q

How do you call a sidebar from your HTML?

A

You call the function dynamic_sidebar()

109
Q

If you call dynamic_sidebar() to show a sidebar, it will not automatically show - what else is required?

A

You have to register the sidebar in the functions.php file. The hook you use is:
add_action( ‘widgets_init’, ‘from_scratch_widgets_init’ );
and within from_scratch_widgets_init function you call register_sidebar (with an array of parameters)

110
Q

Once you have registered the sidebar, and added the code in the HTML to call the sidebar - why doesn’t the widget area show up?

A

You have to add a widget to it before it will show up. It is empty by default.

111
Q

What function is used to register a navigation menu with wordpress?

A

In functions.php make a call to register_nav_menu(). It would be run on the after_theme_setup hook.

add_action ( ‘after_setup_theme’ , ‘from_scratch_register_menu’);

112
Q

What function is used to insert the main menu?

A

wp_nav_menu

113
Q

What is a bit odd about how wp_nav_menu is called?

A

You have to specify a “theme location” which is actually a way of mapping the menu to a name within wordpress (and not the literal theme location).

wp_nav_menu(array(‘theme_location’ => ‘primary’));

In this case, the theme_location is ‘primary’, and this will map to the menu name which was registered in functions.php using the register_nav_menu function, which in turn will display the menu that was selected, in the themes menu screen, next to the “Theme Locations” checkbox.

114
Q

What is the purpose of the add_theme_support function?

A

It allows you to ‘turn on’ features that are not on by default - usually new core features that have not been in the system for a long time.

115
Q

What version was the support for title_tags added to add_theme_support?

A

4.1

116
Q

What is the simplest way to add support to a theme for automatic title-tags?

A

add_theme_support(‘title-tag’);

and it hooks into ‘after_setup_theme’

117
Q

Why might it be necessary to add your own classes to the post_class() function output?

A

Because the output that is provided by default is dependent on the pageview (i.e. is it a post, a sticky post etc).

So - for example, styling posts using the .post class may not catch all cases (if that’s what you want) - for instance, sticky posts do not use it.

118
Q

What is the simplest way to have post-class() method to output a specified class?

A

Just pass a class name as a parameter, it will append it to the list of classes.

Just note: it’s unique to that call, so if you need this to work across files, you either have to do this in each file (bad) or use another method (such as the add_filter method).

119
Q

How do you add a new class to the post_class method such that it is site wide?

A

Use the add_filter function from functions.php.

add_filter ( ‘post_class’, ‘from_scratch_post_class’ );

function from_scratch_post_class($classes) 
{
    $classes[] = 'content-entity';
    return $classes;
}
120
Q

What is the difference between get_template_directory and get_template_directory_uri?

A

get_template_directory gives the file system path for the server, get_template_directory gives the web address.

121
Q

What is one thing to keep in mind regarding child themes when using get_template_directory_uri?

A

If you want a child theme to be able to override the file, then don’t use get_template_directory_uri as it will provide the parent themes template directory, even if called from the child theme.

122
Q

When using get_template_x functions and get_stylesheet_x functions, what’s the difference?

A

get_template_x functions refer to the parent themes directory, whereas get_stylesheet_x functions refer to the child themes directory (if it exists) - so get_stylesheet_x would be the one to use if we wanted the user to be able to overwrite the file using their child theme.

123
Q

What hook do you use to add theme support for featured images?

A

after_setup_theme

124
Q

What feature do you add support for to get featured images?

A

post-thumbnails

it’s an odd name - but it’s an historical issue

125
Q

If you switch themes between a theme that supports featured images (post-thumbnails) and doesn’t support featured-images, what happens to any featured images that are set on a post?

A

Nothing - they will remain and continue to be associated with the post.

126
Q

What function is used to get the featured image?

A

the_post_thumbnail()

127
Q

By default the_post_thumbail creates a massive image (or at least as big as the uploaded image is) - how do you resize it?

A

You must set the default size for the post thumbail in functions.php

128
Q

Other than specifying the exact dimensions in the_post_thumbnail, how else can you specify the size?

A

Use add_image_size() function. Allows you to add a named image size for reference later. i.e.

add_image_size(‘foobar’, 100, 100, false);

Which sets a name called foobar, with height/width of 100 and no crop. Call it later using

the_post_thumbnail( ‘foobar’ );

129
Q

How do you make sure you don’t try to call the_post_thumbnail when no thumbnail is set?

A

use
has_post_thumbnail()
to test

130
Q

What is the difference between
set_post_thumbnail_size(50, 50);
set_post_thumbnail_size(50, 50, true);

A

The first one will create a proportional image, with the max height or width being 50px (but it’s not distorted, so an image can be 40x50).
The second crops the image to be exactly 50 x 50 px.

131
Q

What is the difference between set_post_thumbnail_size and add_image_size?

A

add_image_size allows you to create a named image size, whereas set_post_thumbnail_size sets the default size.

132
Q

If you call “the_post_thumbnail()” with no parameters, what size does it choose?

A

Either post-thumbnail, or whatever is set by set_post_thumbnail_size.

133
Q

What are the reserved post thumbnail size keywords?

A
thumb
thumbnail
medium
large
post-thumbnail
134
Q

What is the difference between a soft and a hard crop (in wordpress parlance)?

A

A soft crop is where the longest dimension is scaled down to the required size, and the shortest dimenion is only cropped if required.

A hard crop is where the image is cropped to fit the specified dimensions no matter what.

135
Q

You’ve just created a new image size (add_image_size), and you’ve specified a hard crop of square dimensions - and you go to the front page and all the images are still rectangles… WHY?

A

Because you have to regenerate your thumbnails in WP to deal with crops that occur after upload. Crops only happen on upload.

Use the plugin - regenerate thumbnails, it works, it’s cool.

136
Q

There are two ways to generate post navigation (i.e. prev / next) - what are they?

A

the_posts_pagination($array) (the new way)

posts_nav_link (the old way)

137
Q

the_posts_pagination and posts_nav_link goes inside or outside the loop?

A

Directly outside, probably immediately after.

138
Q

When dealing with pagination, in wordpress previous means? And next means?

A

Previous always means newer

Next always means older.

139
Q

What controls the number of posts per page when defining pagination?

A

That is done through the front end - under settings/reading.

140
Q

Whats the difference between next_post_link and next_posts_link

A

next_post_link is used on a permalink page of a post to move to the next post. The next_posts_link function is used to customise the “next” posts link for pagination.

141
Q

Is the function get_template_part child theme aware?

A

Yes

142
Q

What is the difference between calling the function

get_template_part( ‘content’, ‘entity’ );
get_template_part( ‘content-entity’ );

A

If the file “content-entity.php” exists, nothing. But the useful thing about calling it like such “get_template_part(‘content’, ‘entity’);” is that you can use the post type to specify the second parameter, and have it load the appropriate template.

143
Q

What function can you use to determine if you are on the front page (in a post) or in a permalink single post?

A

single_page();

144
Q

What function prints out the tags?

A

the_tags()

145
Q

Using the function “the_category()” will create an unordered list, how would you make it a simple comma separated list?

A

Send it an empty string as a parameter.

the_category( ‘ ‘ );

146
Q

How do you get the name of an archive?

A

the_archive_title

147
Q

What function do you call do load the comments template?

A

comments_template();

148
Q

In the comments template file, what do you actually load to load the comments for that post?

A

wp_list_comments(array $args);

149
Q

What is one of the odd features about how you specify whether the comments are wrapped in UL’s?

A

If you specify that the style is “UL”, you still have to wrap the output in your own UL. Weird huh.

150
Q

What is one thing you may need to check regarding comments?

A

If the user requires a password to see or post comments.

post_password_required();

151
Q

It may be worth checking prior to loading the comments template a few things - what might they be?

A

Whether comments are open, and whether any comments actually exist.

comments_open() || get_comments_number()

152
Q

How do you make the “template” option appear in the page creation screen in the CMS?

A

Simply create a file with the header (in the comments) with the field “Template Name: MyTemplateName”. That will then appear in the dropdown.

153
Q

If you don’t want your clients to be able to choose the page template (i.e. the about template should only apply to a page named about) how would you setup this?

A

Make sure you create a “single use” template i.e. it’s a file with the name page-about.php:

page-{slug}.php
page-{pageid}.php

So if the user creates an about page, the content will load that template.

154
Q

Can you add custom fields to a page template?

A

Yes, they will appear in the CMS (use a WP_Query for this). They can be things like the order of the posts.

155
Q

If you create a WP_Query like such:

$q = WP_Query(array(‘ignore_sticky_posts’ => false));

How do you iterate through the resulting posts?

A

Same as for any other time you iterate through posts, however you have to use the object returned by WP_Query.

while ( $q->have_posts() ):
$q->the_post();
endwhile;

156
Q

When you are iterating through a WP_Query object, you are able to access data using the standard functions such as the_title() etc. So what must you do once you exit your loop?

A

You must cleanup everything so that the functions like the_title etc return to pointing to the global state. You do this by calling

wp_reset_postdata();

outside the loop in which you accessed the WP_Query object.

157
Q

What is the recommended screenshot size for a theme?

A

880 x 660px and in png format

158
Q

In order for a screenshot to show up, it should be…

A

named screenshot.png and placed in the root of the theme directory.

159
Q

The logo option in customize is only visible if…

A

You have the Jetpack option enabled.

160
Q

What function do you call to display the jetpack logo?

A

jetpack_the_site_logo

161
Q

How can you customise the logo size output by jetpack_the_site_logo?

A

By default it will display the medium size (as specified by wordpress) - you can pass it a parameter when setting up support for the jetpack logo to specify the size.

    /* Provide support for Jetpack logo */
    $args = array(
        'header-text' => array(
            'site-title',
            'site-description'
        ),
        'size' => 'medium', 
   );
    add_theme_support( 'site-logo', $args );
162
Q

You are adding an icon using genericons via CSS using the Unicode value, and it doesn’t appear, just a square. What is possibly wrong?

A

You may have forgotten to specify the font family (“Genericons”).

163
Q

You have added the comments section, and you are trying to style the “comment-edit-link” so that an edit icon appears before the word edit. But it has brackets around it, and no obvious way to remove them (i.e. “(Edit)”) - how do you remove them?

A

There is no direct way, but by setting up HTML5 support for the comments, you will get output without the brackets. You do this in the functions.php file on an “after_theme_setup” event.

add_theme_support( ‘html5’, array( ‘search-form’, ‘comment-form’, ‘comment-list’, ‘gallery’, ‘caption’ ) );

164
Q

If you are using jQuery in wordpress, you run the risk of conflicts with other libraries, what is the default way to use jQuery?

A

You use jQuery instead of the $ sign.

jQuery(“#mydiv”).css() // etc

165
Q

Instead of typing out jQuery a bazzilion times, what is another method to make that easier?

A

$jq = jQuery.noConflict();

This forces jQuery to relinquish control of the $ symbol. An alternative is to use an IIFE and pass in jQuery and assign it to $.

(function($) {
$(“#mydiv”).css // etc etc
})(jQuery);

166
Q

How do you make a script (such as jQuery) load in the footer instead of the header?

A

Make sure you set the $in_footer variable to true

167
Q

wp_localize_script is used for localising scripts, but it’s also useful for…

A

loading arbitrary javascript, particularly in the case of AJAX scripts. i.e. it can be used to inject an object with data that may be required by an ajax script.

wp_localize_script( ‘kojin_contact_script’, ‘kojin_contact_form_object’,
array (
‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ),
‘security’ => wp_create_nonce( ‘kojin-comment-form-nonce-1312315141324132’ )

                ) // This is the url to the file that will process the request
168
Q

How would you create a nonce for a form?

A

wp_nonce_field(‘chickendick’);

NOTE: wp_nonce_field echoes the data itself.

169
Q

How do you verify a nonce that was sent in an ajax request?

A

check_ajax_referer( ‘process-comment’ );

170
Q

When you are working with AJAX in wordpress, and you want to add your own hooks, what must you do when passing your hook name to the add_action function?

A

You must add the prefix “wp_ajax_” - so if your hook was called - “hide_form”, you have to pass it as “wp_ajax_hide_form”.

171
Q

What is the one caveat with using “wp_ajax_” prefix with hooks when registering them using add_action?

A

It restricts the users that can use it. It would only let admins or people who are logged into the site use the ajax.

172
Q

What prefix do you use on hooks if you want anyone to be able to use your AJAX code?

A

wp_ajax_nopriv_

173
Q

If you want to trigger an ajax action for both logged in and non-logged in users, how would you set that hook up?

A

You would need to add the hook for both priv and non-priv users.

add_action(‘wp_ajax_my_action’, ‘my_hook_callback’);
add_action(‘wp_ajax_nopriv_my_action, ‘my_hook_callback’);

function my_hook_callback() 
{
   // Do cool ajax related things here
}
174
Q

How is wp_ajax_(action) mapped to the front end?

A

In the ajax call, you have to specify the action name. This would typically be the part of the url that calls the backend code (you might grab this from the ‘action’ attribute in the form typically).

In wordpress - you will point a callback to an action, which will be the name of the action (“my_action”) with the wp_ajax_ prefix.

‘wp_ajax_my_action’

This is referenced in the PHP when you register the callback.
add_action(‘wp_ajax_my_action’, ‘my_action_callback’);

In the ajax front end - the ‘action’ field refers to ‘my_action’.

175
Q

When you are registering an AJAX script for the front-end (using wp_localize_script) you will have to specify a variable name that will hold the data being passed to the script. What is one catch?

A

Because the name represents a JavaScript object, you will not be able to use hyphens in the variable name, you have to use camelCase or under_scores.

176
Q

Front end and back end ajax in wordpress both use admin-ajax.php file. What is the implication for detecting whether we are using admin AJAX?

A

is_admin() will return true in both contexts.

177
Q

AJAX Scripts that are bound to either wp_ajax_ and wp_ajax_nopriv_, are both run in the WP Admin context, which means you have to be careful of…

A

Security, you must run them from within is_admin() == true block.

178
Q

If you are using AJAX in wordpress, what do you have to remember when setting up the hooks?

A

You have to call them from within is_admin() == true block, or else they are not set correctly.

179
Q

What function can you use to determine whether an ajax form was sent from the site?

A

check_ajax_referer

180
Q

What is the best function for cleaning up input from a user input text field?

A

sanitize_text_field($variable)

181
Q

How do you stop fields from going yellow?

A

You may be hitting the “automcomplete” functionality. If you don’t need it, use autocomplete=”off” on the form, or the individual inputs.

NOTE: This probably doesn’t work in Chrome, because apparently the developers are arseholes (seriously, check the thread on this).

182
Q

If you create a DOM element using jQuery like such

var myelement = $("insert single UL tag here");
And then you use append, to add an LI element..

Do you need to close the UL tag?

A

No, jQuery takes care of that

183
Q

Since wp 2.7, threaded comments have been supported, what do we need to enqueue in order to support this, and is this a required feature?

A

Yes, this is a required feature (it will be highlighted in the theme tests).

if (is_singular() && comments_open() && get_option(‘thread_comments) {

wp_enqueue_script( ‘comment-reply’ );
}

Within the actual comments template, you should test that the user has permission to post.

184
Q

When you get the following error in the theme checker, to what does this refer?

WARNING: Found wrong tag, remove from your style.css header.

A

The “tags” section in the comments at the top of the style.css page. Remember, only WP approved tags can be added here, even looking for a trailing comma.

185
Q

How do you register a widget?

A

add_action( ‘widgets_init’, function() {
register_widget( ‘Class_Name’ );
});

186
Q

What is a .po file?

A

It’s a file for localisation that can be edited by users of a program called poedit.

187
Q

How do you tell wordpress where the localisation files are for your plugin?

A

Make a call to add_action in the init event.

add_action( ‘init’, array($this, ‘widget_textdomain’ ) );

NOTE: This is passing the name of a method ‘widget_textdomain’, and the context ($this) to wordpress via the add_action api. You must of course write and provide that function yourself. You need to inform wordpress of the appropriate text domain.

188
Q

What does load_pluging_textdomain() do?

A

Calling it like so:

load_plugin_textdomain( ‘front-to-back’, false, plugin_dir_path( __FILE__ ) . ‘/lang/’ );

You are loading the localisation strings.

189
Q

How do you actually setup a string for localisation?

A

You wrap the text in the function __() and pass it the id for the localisation (the same string id used in the load_plugin_textdomain function.

i.e.

__( ‘I like eating chickens’, ‘front-to-back’ )

190
Q

What is the transient API?

A

It is an api that provides short term caching for requests. For example, the flickr api has a limit on the number of requests you can make. So using the transient api could alleviate the impact on the server.