php function not work as expected
-
Hi all!!
i’m quite new to creating my own functions….
I’m struggling to understand why my function “serviced_office_title” does not display within the <h1 class=”trail-title”></h1>, the function works but is above the H1 tag.
my assumption was if i replaced “$flash_header_title” with my function
i.e $flash_header_title = serviced_office_title();then whatever “serviced_office_title()” creates would replace “$flash_header_title”
echo ‘<h1 class=”trail-title”>’;
echo $flash_header_title; <<< my title here???
echo ‘</h1>’;this is what happens – not inside the H1 tag
<div class="tg-container"> Bishops Home Builders - 2A <h1 class="trail-title"></h1> <ul class="trail-items"><li class="trail-item trail-begin"><a class="trail-home" href="" title="Home"><span>Home</span></a></li><li class="trail-item"><a class="item-custom-post-type" href="" title="Serviced Offices"><span>Serviced Offices</span></a></li><li class="trail-item"><span>Bishops Home Builders</span></li></ul></div>
where am i going wrong? have i made the wrong assumption?? can anyone help?
if ( ! function_exists( 'flash_page_title' ) ) : /** * Title for page header * * @since Flash 1.0 */ function flash_page_title() { if ( is_archive() ) { $flash_header_title = get_the_archive_title(); } elseif ( is_404() ) { $flash_header_title = esc_html__( 'Page NOT Found', 'flash' ); } elseif ( is_search() ) { $flash_header_title = sprintf( esc_html__( 'Search Results for: %s', 'flash' ), esc_html( get_search_query() ) ); }elseif ( is_singular('serviced-office')) { $flash_header_title = serviced_office_title(); } elseif ( is_singular() ) { $flash_header_title = get_the_title(); } elseif ( is_home() ) { $queried_id = get_option( 'page_for_posts' ); $flash_header_title = get_the_title( $queried_id ); } else { $flash_header_title = ''; } if ( flash_is_woocommerce_page() ) { $flash_header_title = woocommerce_page_title( $echo = false ); } echo '<h1 class="trail-title">'; echo $flash_header_title; echo '</h1>'; } endif; if ( ! function_exists( 'serviced_office_title' ) ) : /** * Title for page header * * @since Flash 1.0 */ function serviced_office_title() { if( get_field('is_this_office_available')=='yes' ){ echo the_field('office_number'); } elseif( get_field('is_this_office_available')=='no' ){ echo get_the_title(); echo ' - '; echo the_field('office_number'); } } endif;
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘php function not work as expected’ is closed to new replies.