Hooks
The starter theme offers a handful of hooks and filters to tap into and customize WordPress functionality. Here is a list of what we include and how to use it in your theme.
add_og_tags()
Sometimes a client don't use Yoast SEO or another SEO plugin. In those cases, we still want to make sure they have reliable meta tags in place to display robust post cards when content is shared via Facebook, Twitter, etc.
This hook first checks to see if Yoast is active – we don't need to output 2x meta tags.
If Yoast isn't active, we build our meta tags based on a set of conditions as we go:
- Single posts and pages (but not the front page)
- Category, Tag, and Custom Taxonomy archives
- Search Results
- Blog archive
- Front page
- Post Type archives
- Media pages
Output:
<meta property="og:title" content="Featured Image (Vertical) - wd_s" />
<meta
property="og:description"
content="This post should display a featured image, if the theme supports it. Non-square images can provide some unique styling issues. This post tests a vertical featured image."
/>
<meta
property="og:url"
content="https://wdunderscores.test/2013/03/15/featured-image-vertical/"
/>
<meta
property="og:image"
content="https://wdunderscores.test/wp-content/uploads/2013/03/featured-image-vertical.jpg"
/>
<meta property="og:site_name" content="wd_s" />
<meta property="og:type" content="article" />
<meta
name="description"
content="This post should display a featured image, if the theme supports it. Non-square images can provide some unique styling issues. This post tests a vertical featured image."
/>
body_classes()
Add classes to the <body> tag.
Usage:
add_filter( 'body_class', __NAMESPACE__ . '\body_classes' );
Output:
Adds class names to the <body> tag based on the location, template type, or browser type.
Add SVG Support custom_mime_types()
Add custom mime types to allow for uploading SVG images. Typically a plugin like Safe SVG is used for more customization.
Disable Comments
This file disables comments across the site.
excerpt_more()
Customize the [...] on the_excerpt()
Usage: $content = get_post_content( $content );
include_svg_icons()
Adds the SVG Sprite that is generated to the footer so they can be displayed via the SVG template tag.
print_header_scripts()
Display the theme settings scripts in the header. Best used for various tracking tags.
print_footer_scripts()
Display the theme settings scripts in the footer. Best used for various tracking tags.
remove_archive_title_prefix()
Removes or Adjusts the prefix on category archive page titles.