-
Notifications
You must be signed in to change notification settings - Fork 136
Functions
Not a hook or a filter? Not a template tag used to output something directly in a template or template part? Then you've come to the right place! Our /inc/functions/
directory provides functions that act independently of the theme templates.
get_categorized_blog
Returns true if a blog has more than 1 category.
Usage:
if ( get_categorized_blog() ) {
// There are several categories
} else {
// There is only one category
}
Output: There is no output; this template tag returns true
or false
depending on the number of categories present on a site.
Location: /inc/functions/get-categorized-blog.php
get_attachment_id_from_url
Get an attachment ID from its URL.
Usage: <?php echo get_attachment_id_from_url( 'https://wdunderscores.test/wp-content/uploads/2013/03/man-of-steel.jpg' ); ?>
Output: 1040
Location: /inc/functions/get-attachment-id-from-url.php
get_svg
Outputted by the print_svg
function (inside inc/template-tags/print-svg.php
) and accepts the same args that function.
Usage:
get_svg( array(
'icon' => 'facebook-square',
'title' => __( 'Facebook square icon', '_s' ),
'desc' => __( 'A rounded square version of the Facebook logo', '_s' ),
'color' => '#ffff00',
'stroke-width' => '0.5',
'height' => '48',
'width' => '48',
)
);
Output
Stringified svg
<svg
height="48"
width="48"
color="#ffff00"
stroke-width="0.5"
class="icon facebook-square"
aria-labelledby="title-facebook-square-icon-67297 desc-facebook-square-icon-67297"
role="img"
>
<title id="title-facebook-square-icon-67297">Facebook square icon</title>
<desc id="desc-facebook-square-icon-67297">
A rounded square version of the Facebook logo
</desc>
<use xlink:href="#facebook-square"></use>
</svg>
Location: /inc/functions/get-svg.php
get_custom_logo_url
Get the URL of the custom logo uploaded, if one exists.
Usage:
if ( get_custom_logo_url() ) {
// do something
}
Output: Returns the custom logo url if it exists, otherwise returns false
Location: /inc/functions/get-custom-logo-url.php
get_trimmed_excerpt
Limit the excerpt length
Usage:
get_trimmed_excerpt( array(
'length' => 20,
'more' => '...',
'post' => '',
)
);
Output: Returns the trimmed excerpt
Location: /inc/functions/get-trimmed-excerpt.php
get_trimmed_title
Limit the title length
Usage:
get_trimmed_title( array(
'length' => 12,
'more' => '...',
)
);
Output: Returns the trimmed title
Location: /inc/functions/get-trimmed-title.php