Edit File by line
/home/barbar84/www/wp-inclu...
File: post-template.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Post Template Functions.
[2] Fix | Delete
*
[3] Fix | Delete
* Gets content for the current post in the loop.
[4] Fix | Delete
*
[5] Fix | Delete
* @package WordPress
[6] Fix | Delete
* @subpackage Template
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Display the ID of the current item in the WordPress Loop.
[11] Fix | Delete
*
[12] Fix | Delete
* @since 0.71
[13] Fix | Delete
*/
[14] Fix | Delete
function the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
[15] Fix | Delete
echo get_the_ID();
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Retrieve the ID of the current item in the WordPress Loop.
[20] Fix | Delete
*
[21] Fix | Delete
* @since 2.1.0
[22] Fix | Delete
*
[23] Fix | Delete
* @return int|false The ID of the current item in the WordPress Loop. False if $post is not set.
[24] Fix | Delete
*/
[25] Fix | Delete
function get_the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
[26] Fix | Delete
$post = get_post();
[27] Fix | Delete
return ! empty( $post ) ? $post->ID : false;
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Display or retrieve the current post title with optional markup.
[32] Fix | Delete
*
[33] Fix | Delete
* @since 0.71
[34] Fix | Delete
*
[35] Fix | Delete
* @param string $before Optional. Markup to prepend to the title. Default empty.
[36] Fix | Delete
* @param string $after Optional. Markup to append to the title. Default empty.
[37] Fix | Delete
* @param bool $echo Optional. Whether to echo or return the title. Default true for echo.
[38] Fix | Delete
* @return void|string Void if `$echo` argument is true, current post title if `$echo` is false.
[39] Fix | Delete
*/
[40] Fix | Delete
function the_title( $before = '', $after = '', $echo = true ) {
[41] Fix | Delete
$title = get_the_title();
[42] Fix | Delete
[43] Fix | Delete
if ( strlen( $title ) == 0 ) {
[44] Fix | Delete
return;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
$title = $before . $title . $after;
[48] Fix | Delete
[49] Fix | Delete
if ( $echo ) {
[50] Fix | Delete
echo $title;
[51] Fix | Delete
} else {
[52] Fix | Delete
return $title;
[53] Fix | Delete
}
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Sanitize the current title when retrieving or displaying.
[58] Fix | Delete
*
[59] Fix | Delete
* Works like the_title(), except the parameters can be in a string or
[60] Fix | Delete
* an array. See the function for what can be override in the $args parameter.
[61] Fix | Delete
*
[62] Fix | Delete
* The title before it is displayed will have the tags stripped and esc_attr()
[63] Fix | Delete
* before it is passed to the user or displayed. The default as with the_title(),
[64] Fix | Delete
* is to display the title.
[65] Fix | Delete
*
[66] Fix | Delete
* @since 2.3.0
[67] Fix | Delete
*
[68] Fix | Delete
* @param string|array $args {
[69] Fix | Delete
* Title attribute arguments. Optional.
[70] Fix | Delete
*
[71] Fix | Delete
* @type string $before Markup to prepend to the title. Default empty.
[72] Fix | Delete
* @type string $after Markup to append to the title. Default empty.
[73] Fix | Delete
* @type bool $echo Whether to echo or return the title. Default true for echo.
[74] Fix | Delete
* @type WP_Post $post Current post object to retrieve the title for.
[75] Fix | Delete
* }
[76] Fix | Delete
* @return void|string Void if 'echo' argument is true, the title attribute if 'echo' is false.
[77] Fix | Delete
*/
[78] Fix | Delete
function the_title_attribute( $args = '' ) {
[79] Fix | Delete
$defaults = array(
[80] Fix | Delete
'before' => '',
[81] Fix | Delete
'after' => '',
[82] Fix | Delete
'echo' => true,
[83] Fix | Delete
'post' => get_post(),
[84] Fix | Delete
);
[85] Fix | Delete
$parsed_args = wp_parse_args( $args, $defaults );
[86] Fix | Delete
[87] Fix | Delete
$title = get_the_title( $parsed_args['post'] );
[88] Fix | Delete
[89] Fix | Delete
if ( strlen( $title ) == 0 ) {
[90] Fix | Delete
return;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
$title = $parsed_args['before'] . $title . $parsed_args['after'];
[94] Fix | Delete
$title = esc_attr( strip_tags( $title ) );
[95] Fix | Delete
[96] Fix | Delete
if ( $parsed_args['echo'] ) {
[97] Fix | Delete
echo $title;
[98] Fix | Delete
} else {
[99] Fix | Delete
return $title;
[100] Fix | Delete
}
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Retrieve post title.
[105] Fix | Delete
*
[106] Fix | Delete
* If the post is protected and the visitor is not an admin, then "Protected"
[107] Fix | Delete
* will be displayed before the post title. If the post is private, then
[108] Fix | Delete
* "Private" will be located before the post title.
[109] Fix | Delete
*
[110] Fix | Delete
* @since 0.71
[111] Fix | Delete
*
[112] Fix | Delete
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
[113] Fix | Delete
* @return string
[114] Fix | Delete
*/
[115] Fix | Delete
function get_the_title( $post = 0 ) {
[116] Fix | Delete
$post = get_post( $post );
[117] Fix | Delete
[118] Fix | Delete
$title = isset( $post->post_title ) ? $post->post_title : '';
[119] Fix | Delete
$id = isset( $post->ID ) ? $post->ID : 0;
[120] Fix | Delete
[121] Fix | Delete
if ( ! is_admin() ) {
[122] Fix | Delete
if ( ! empty( $post->post_password ) ) {
[123] Fix | Delete
[124] Fix | Delete
/* translators: %s: Protected post title. */
[125] Fix | Delete
$prepend = __( 'Protected: %s' );
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Filters the text prepended to the post title for protected posts.
[129] Fix | Delete
*
[130] Fix | Delete
* The filter is only applied on the front end.
[131] Fix | Delete
*
[132] Fix | Delete
* @since 2.8.0
[133] Fix | Delete
*
[134] Fix | Delete
* @param string $prepend Text displayed before the post title.
[135] Fix | Delete
* Default 'Protected: %s'.
[136] Fix | Delete
* @param WP_Post $post Current post object.
[137] Fix | Delete
*/
[138] Fix | Delete
$protected_title_format = apply_filters( 'protected_title_format', $prepend, $post );
[139] Fix | Delete
$title = sprintf( $protected_title_format, $title );
[140] Fix | Delete
} elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) {
[141] Fix | Delete
[142] Fix | Delete
/* translators: %s: Private post title. */
[143] Fix | Delete
$prepend = __( 'Private: %s' );
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Filters the text prepended to the post title of private posts.
[147] Fix | Delete
*
[148] Fix | Delete
* The filter is only applied on the front end.
[149] Fix | Delete
*
[150] Fix | Delete
* @since 2.8.0
[151] Fix | Delete
*
[152] Fix | Delete
* @param string $prepend Text displayed before the post title.
[153] Fix | Delete
* Default 'Private: %s'.
[154] Fix | Delete
* @param WP_Post $post Current post object.
[155] Fix | Delete
*/
[156] Fix | Delete
$private_title_format = apply_filters( 'private_title_format', $prepend, $post );
[157] Fix | Delete
$title = sprintf( $private_title_format, $title );
[158] Fix | Delete
}
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
/**
[162] Fix | Delete
* Filters the post title.
[163] Fix | Delete
*
[164] Fix | Delete
* @since 0.71
[165] Fix | Delete
*
[166] Fix | Delete
* @param string $title The post title.
[167] Fix | Delete
* @param int $id The post ID.
[168] Fix | Delete
*/
[169] Fix | Delete
return apply_filters( 'the_title', $title, $id );
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Display the Post Global Unique Identifier (guid).
[174] Fix | Delete
*
[175] Fix | Delete
* The guid will appear to be a link, but should not be used as a link to the
[176] Fix | Delete
* post. The reason you should not use it as a link, is because of moving the
[177] Fix | Delete
* blog across domains.
[178] Fix | Delete
*
[179] Fix | Delete
* URL is escaped to make it XML-safe.
[180] Fix | Delete
*
[181] Fix | Delete
* @since 1.5.0
[182] Fix | Delete
*
[183] Fix | Delete
* @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
[184] Fix | Delete
*/
[185] Fix | Delete
function the_guid( $post = 0 ) {
[186] Fix | Delete
$post = get_post( $post );
[187] Fix | Delete
[188] Fix | Delete
$guid = isset( $post->guid ) ? get_the_guid( $post ) : '';
[189] Fix | Delete
$id = isset( $post->ID ) ? $post->ID : 0;
[190] Fix | Delete
[191] Fix | Delete
/**
[192] Fix | Delete
* Filters the escaped Global Unique Identifier (guid) of the post.
[193] Fix | Delete
*
[194] Fix | Delete
* @since 4.2.0
[195] Fix | Delete
*
[196] Fix | Delete
* @see get_the_guid()
[197] Fix | Delete
*
[198] Fix | Delete
* @param string $guid Escaped Global Unique Identifier (guid) of the post.
[199] Fix | Delete
* @param int $id The post ID.
[200] Fix | Delete
*/
[201] Fix | Delete
echo apply_filters( 'the_guid', $guid, $id );
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
/**
[205] Fix | Delete
* Retrieve the Post Global Unique Identifier (guid).
[206] Fix | Delete
*
[207] Fix | Delete
* The guid will appear to be a link, but should not be used as an link to the
[208] Fix | Delete
* post. The reason you should not use it as a link, is because of moving the
[209] Fix | Delete
* blog across domains.
[210] Fix | Delete
*
[211] Fix | Delete
* @since 1.5.0
[212] Fix | Delete
*
[213] Fix | Delete
* @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
[214] Fix | Delete
* @return string
[215] Fix | Delete
*/
[216] Fix | Delete
function get_the_guid( $post = 0 ) {
[217] Fix | Delete
$post = get_post( $post );
[218] Fix | Delete
[219] Fix | Delete
$guid = isset( $post->guid ) ? $post->guid : '';
[220] Fix | Delete
$id = isset( $post->ID ) ? $post->ID : 0;
[221] Fix | Delete
[222] Fix | Delete
/**
[223] Fix | Delete
* Filters the Global Unique Identifier (guid) of the post.
[224] Fix | Delete
*
[225] Fix | Delete
* @since 1.5.0
[226] Fix | Delete
*
[227] Fix | Delete
* @param string $guid Global Unique Identifier (guid) of the post.
[228] Fix | Delete
* @param int $id The post ID.
[229] Fix | Delete
*/
[230] Fix | Delete
return apply_filters( 'get_the_guid', $guid, $id );
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
/**
[234] Fix | Delete
* Display the post content.
[235] Fix | Delete
*
[236] Fix | Delete
* @since 0.71
[237] Fix | Delete
*
[238] Fix | Delete
* @param string $more_link_text Optional. Content for when there is more text.
[239] Fix | Delete
* @param bool $strip_teaser Optional. Strip teaser content before the more text. Default false.
[240] Fix | Delete
*/
[241] Fix | Delete
function the_content( $more_link_text = null, $strip_teaser = false ) {
[242] Fix | Delete
$content = get_the_content( $more_link_text, $strip_teaser );
[243] Fix | Delete
[244] Fix | Delete
/**
[245] Fix | Delete
* Filters the post content.
[246] Fix | Delete
*
[247] Fix | Delete
* @since 0.71
[248] Fix | Delete
*
[249] Fix | Delete
* @param string $content Content of the current post.
[250] Fix | Delete
*/
[251] Fix | Delete
$content = apply_filters( 'the_content', $content );
[252] Fix | Delete
$content = str_replace( ']]>', ']]&gt;', $content );
[253] Fix | Delete
echo $content;
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Retrieve the post content.
[258] Fix | Delete
*
[259] Fix | Delete
* @since 0.71
[260] Fix | Delete
* @since 5.2.0 Added the `$post` parameter.
[261] Fix | Delete
*
[262] Fix | Delete
* @global int $page Page number of a single post/page.
[263] Fix | Delete
* @global int $more Boolean indicator for whether single post/page is being viewed.
[264] Fix | Delete
* @global bool $preview Whether post/page is in preview mode.
[265] Fix | Delete
* @global array $pages Array of all pages in post/page. Each array element contains
[266] Fix | Delete
* part of the content separated by the `<!--nextpage-->` tag.
[267] Fix | Delete
* @global int $multipage Boolean indicator for whether multiple pages are in play.
[268] Fix | Delete
*
[269] Fix | Delete
* @param string $more_link_text Optional. Content for when there is more text.
[270] Fix | Delete
* @param bool $strip_teaser Optional. Strip teaser content before the more text. Default false.
[271] Fix | Delete
* @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default null.
[272] Fix | Delete
* @return string
[273] Fix | Delete
*/
[274] Fix | Delete
function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
[275] Fix | Delete
global $page, $more, $preview, $pages, $multipage;
[276] Fix | Delete
[277] Fix | Delete
$_post = get_post( $post );
[278] Fix | Delete
[279] Fix | Delete
if ( ! ( $_post instanceof WP_Post ) ) {
[280] Fix | Delete
return '';
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
// Use the globals if the $post parameter was not specified,
[284] Fix | Delete
// but only after they have been set up in setup_postdata().
[285] Fix | Delete
if ( null === $post && did_action( 'the_post' ) ) {
[286] Fix | Delete
$elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
[287] Fix | Delete
} else {
[288] Fix | Delete
$elements = generate_postdata( $_post );
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
if ( null === $more_link_text ) {
[292] Fix | Delete
$more_link_text = sprintf(
[293] Fix | Delete
'<span aria-label="%1$s">%2$s</span>',
[294] Fix | Delete
sprintf(
[295] Fix | Delete
/* translators: %s: Post title. */
[296] Fix | Delete
__( 'Continue reading %s' ),
[297] Fix | Delete
the_title_attribute(
[298] Fix | Delete
array(
[299] Fix | Delete
'echo' => false,
[300] Fix | Delete
'post' => $_post,
[301] Fix | Delete
)
[302] Fix | Delete
)
[303] Fix | Delete
),
[304] Fix | Delete
__( '(more&hellip;)' )
[305] Fix | Delete
);
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
$output = '';
[309] Fix | Delete
$has_teaser = false;
[310] Fix | Delete
[311] Fix | Delete
// If post password required and it doesn't match the cookie.
[312] Fix | Delete
if ( post_password_required( $_post ) ) {
[313] Fix | Delete
return get_the_password_form( $_post );
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
// If the requested page doesn't exist.
[317] Fix | Delete
if ( $elements['page'] > count( $elements['pages'] ) ) {
[318] Fix | Delete
// Give them the highest numbered page that DOES exist.
[319] Fix | Delete
$elements['page'] = count( $elements['pages'] );
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
$page_no = $elements['page'];
[323] Fix | Delete
$content = $elements['pages'][ $page_no - 1 ];
[324] Fix | Delete
if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
[325] Fix | Delete
if ( has_block( 'more', $content ) ) {
[326] Fix | Delete
// Remove the core/more block delimiters. They will be left over after $content is split up.
[327] Fix | Delete
$content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
$content = explode( $matches[0], $content, 2 );
[331] Fix | Delete
[332] Fix | Delete
if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
[333] Fix | Delete
$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
$has_teaser = true;
[337] Fix | Delete
} else {
[338] Fix | Delete
$content = array( $content );
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
if ( false !== strpos( $_post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || 1 == $elements['page'] ) ) {
[342] Fix | Delete
$strip_teaser = true;
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
$teaser = $content[0];
[346] Fix | Delete
[347] Fix | Delete
if ( $elements['more'] && $strip_teaser && $has_teaser ) {
[348] Fix | Delete
$teaser = '';
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
$output .= $teaser;
[352] Fix | Delete
[353] Fix | Delete
if ( count( $content ) > 1 ) {
[354] Fix | Delete
if ( $elements['more'] ) {
[355] Fix | Delete
$output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1];
[356] Fix | Delete
} else {
[357] Fix | Delete
if ( ! empty( $more_link_text ) ) {
[358] Fix | Delete
[359] Fix | Delete
/**
[360] Fix | Delete
* Filters the Read More link text.
[361] Fix | Delete
*
[362] Fix | Delete
* @since 2.8.0
[363] Fix | Delete
*
[364] Fix | Delete
* @param string $more_link_element Read More link element.
[365] Fix | Delete
* @param string $more_link_text Read More text.
[366] Fix | Delete
*/
[367] Fix | Delete
$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink( $_post ) . "#more-{$_post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
[368] Fix | Delete
}
[369] Fix | Delete
$output = force_balance_tags( $output );
[370] Fix | Delete
}
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
return $output;
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
/**
[377] Fix | Delete
* Display the post excerpt.
[378] Fix | Delete
*
[379] Fix | Delete
* @since 0.71
[380] Fix | Delete
*/
[381] Fix | Delete
function the_excerpt() {
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* Filters the displayed post excerpt.
[385] Fix | Delete
*
[386] Fix | Delete
* @since 0.71
[387] Fix | Delete
*
[388] Fix | Delete
* @see get_the_excerpt()
[389] Fix | Delete
*
[390] Fix | Delete
* @param string $post_excerpt The post excerpt.
[391] Fix | Delete
*/
[392] Fix | Delete
echo apply_filters( 'the_excerpt', get_the_excerpt() );
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
/**
[396] Fix | Delete
* Retrieves the post excerpt.
[397] Fix | Delete
*
[398] Fix | Delete
* @since 0.71
[399] Fix | Delete
* @since 4.5.0 Introduced the `$post` parameter.
[400] Fix | Delete
*
[401] Fix | Delete
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
[402] Fix | Delete
* @return string Post excerpt.
[403] Fix | Delete
*/
[404] Fix | Delete
function get_the_excerpt( $post = null ) {
[405] Fix | Delete
if ( is_bool( $post ) ) {
[406] Fix | Delete
_deprecated_argument( __FUNCTION__, '2.3.0' );
[407] Fix | Delete
}
[408] Fix | Delete
[409] Fix | Delete
$post = get_post( $post );
[410] Fix | Delete
if ( empty( $post ) ) {
[411] Fix | Delete
return '';
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
if ( post_password_required( $post ) ) {
[415] Fix | Delete
return __( 'There is no excerpt because this is a protected post.' );
[416] Fix | Delete
}
[417] Fix | Delete
[418] Fix | Delete
/**
[419] Fix | Delete
* Filters the retrieved post excerpt.
[420] Fix | Delete
*
[421] Fix | Delete
* @since 1.2.0
[422] Fix | Delete
* @since 4.5.0 Introduced the `$post` parameter.
[423] Fix | Delete
*
[424] Fix | Delete
* @param string $post_excerpt The post excerpt.
[425] Fix | Delete
* @param WP_Post $post Post object.
[426] Fix | Delete
*/
[427] Fix | Delete
return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
/**
[431] Fix | Delete
* Determines whether the post has a custom excerpt.
[432] Fix | Delete
*
[433] Fix | Delete
* For more information on this and similar theme functions, check out
[434] Fix | Delete
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
[435] Fix | Delete
* Conditional Tags} article in the Theme Developer Handbook.
[436] Fix | Delete
*
[437] Fix | Delete
* @since 2.3.0
[438] Fix | Delete
*
[439] Fix | Delete
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
[440] Fix | Delete
* @return bool True if the post has a custom excerpt, false otherwise.
[441] Fix | Delete
*/
[442] Fix | Delete
function has_excerpt( $post = 0 ) {
[443] Fix | Delete
$post = get_post( $post );
[444] Fix | Delete
return ( ! empty( $post->post_excerpt ) );
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
/**
[448] Fix | Delete
* Displays the classes for the post container element.
[449] Fix | Delete
*
[450] Fix | Delete
* @since 2.7.0
[451] Fix | Delete
*
[452] Fix | Delete
* @param string|string[] $class One or more classes to add to the class list.
[453] Fix | Delete
* @param int|WP_Post $post_id Optional. Post ID or post object. Defaults to the global `$post`.
[454] Fix | Delete
*/
[455] Fix | Delete
function post_class( $class = '', $post_id = null ) {
[456] Fix | Delete
// Separates classes with a single space, collates classes for post DIV.
[457] Fix | Delete
echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post_id ) ) ) . '"';
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
/**
[461] Fix | Delete
* Retrieves an array of the class names for the post container element.
[462] Fix | Delete
*
[463] Fix | Delete
* The class names are many. If the post is a sticky, then the 'sticky'
[464] Fix | Delete
* class name. The class 'hentry' is always added to each post. If the post has a
[465] Fix | Delete
* post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that
[466] Fix | Delete
* the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' -
[467] Fix | Delete
* eg 'category-foo' or 'my_custom_taxonomy-bar'.
[468] Fix | Delete
*
[469] Fix | Delete
* The 'post_tag' taxonomy is a special
[470] Fix | Delete
* case; the class has the 'tag-' prefix instead of 'post_tag-'. All class names are
[471] Fix | Delete
* passed through the filter, {@see 'post_class'}, with the list of class names, followed by
[472] Fix | Delete
* $class parameter value, with the post ID as the last parameter.
[473] Fix | Delete
*
[474] Fix | Delete
* @since 2.7.0
[475] Fix | Delete
* @since 4.2.0 Custom taxonomy class names were added.
[476] Fix | Delete
*
[477] Fix | Delete
* @param string|string[] $class Space-separated string or array of class names to add to the class list.
[478] Fix | Delete
* @param int|WP_Post $post_id Optional. Post ID or post object.
[479] Fix | Delete
* @return string[] Array of class names.
[480] Fix | Delete
*/
[481] Fix | Delete
function get_post_class( $class = '', $post_id = null ) {
[482] Fix | Delete
$post = get_post( $post_id );
[483] Fix | Delete
[484] Fix | Delete
$classes = array();
[485] Fix | Delete
[486] Fix | Delete
if ( $class ) {
[487] Fix | Delete
if ( ! is_array( $class ) ) {
[488] Fix | Delete
$class = preg_split( '#\s+#', $class );
[489] Fix | Delete
}
[490] Fix | Delete
$classes = array_map( 'esc_attr', $class );
[491] Fix | Delete
} else {
[492] Fix | Delete
// Ensure that we always coerce class to being an array.
[493] Fix | Delete
$class = array();
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
if ( ! $post ) {
[497] Fix | Delete
return $classes;
[498] Fix | Delete
}
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function