How to Make Simple Edit to PHP/Function file in WordPress
-
I know basically nothing about php and would love someone’s help regarding the following edit I’m trying to make on my WordPress website.
Here is the current and working section of the code I’m trying to edit:
elseif ( is_singular( 'post' ) ) { $title = get_the_title(); $subtitle = get_the_date() . ' - ' . get_the_category_list( ', ' );Here is what I’d like to add to the code above:
Published:
Updated:<?php echo date('j F Y'); ?>Here is what I’ve tried without success:
elseif ( is_singular( 'post' ) ) { $title = get_the_title(); $subtitle = 'Published:' get_the_date() . ' - ' . get_the_category_list( ', ' ) 'Updated: <?php echo date('j F Y'); ?>';Additionally, it would actually be amazing if someone could help me make the edits noted above to apply strictly to a certain post category (as the above will be applied to all ‘post'(s).
For more information or parameters, below is the full section of code as it appears in my functions.php file:
function rainy_page_header() { $title = ''; $subtitle = ''; if ( is_front_page() && is_home() ) { $title = get_theme_mod( 'rainy_default_blog_title', 'Blog' ); $subtitle = get_theme_mod( 'rainy_default_blog_subtitle', 'Blog subtitle' ); } elseif ( is_singular( 'post' ) ) { $title = get_the_title(); $subtitle = get_the_date() . ' - ' . get_the_category_list( ', ' ); } elseif ( is_home() ) { $blog = get_post( get_option( 'page_for_posts' ) ); $title = $blog->post_title; $subtitle = get_post_meta( $blog->ID, 'rainy_subtitle', true ); } elseif ( is_tax() ) { $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $title = $term->name; $subtitle = category_description(); } elseif ( is_category() ) { $title = single_cat_title( '', false ); $subtitle = category_description(); } elseif ( is_tag() ) { $title = single_tag_title( '', false ); $subtitle = tag_description(); } elseif ( is_day() ) { $title = get_the_date(); $subtitle = __( 'Daily archives', 'spartan01' ); } elseif ( is_month() ) { $title = get_the_date( 'F Y' ); $subtitle = __( 'Monthly archives', 'spartan01' ); } elseif ( is_year() ) { $title = get_the_date( 'Y' ); $subtitle = __( 'Yearly archives', 'spartan01' ); } elseif ( is_author() ) { $title = get_the_author(); $subtitle = __( 'Author archives', 'spartan01' ); } elseif ( is_search() ) { $title = __( 'Search results for: ', 'spartan01' ) . get_search_query(); } elseif ( is_404() ) { $title = __( 'Error 404', 'spartan01' ); $subtitle = __( 'Page not found', 'spartan01' ); } else { $title = get_the_title(); $subtitle = get_post_meta( get_the_ID(), 'rainy_subtitle', true ); } echo '<div class="page-header">'; echo '<h1 class="page-title">' . $title . '</h1>'; if ( $subtitle ) { echo '<div class="page-subtitle">' . $subtitle . '</div>'; } echo '</div>'; }Any help/support is greatly appreciated.
The topic ‘How to Make Simple Edit to PHP/Function file in WordPress’ is closed to new replies.