1

I'm trying to override Fancy Title created using The7 Theme. The7 Titles are generate from this function:

function presscore_get_page_title() {
    $title = '';

    if ( is_page() || is_single() ) {
        $title = get_the_title();

    } else if ( is_search() ) {
        $title = sprintf( __( 'Search Results for: %s', 'the7mk2' ), '<span>' . get_search_query() . '</span>' );

    } else if ( is_archive() ) {

        if ( is_category() ) {
            $title = sprintf( __( 'Category Archives: %s', 'the7mk2' ), '<span>' . single_cat_title( '', false ) . '</span>' );

        } elseif ( is_tag() ) {
            $title = sprintf( __( 'Tag Archives: %s', 'the7mk2' ), '<span>' . single_tag_title( '', false ) . '</span>' );

        } elseif ( is_author() ) {
            the_post();
            $title = sprintf( __( 'Author Archives: %s', 'the7mk2' ), '<span class="vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( "ID" ) ) ) . '" title="' . esc_attr( get_the_author() ) . '" rel="me">' . get_the_author() . '</a></span>' );
            rewind_posts();

        } elseif ( is_day() ) {
            $title = sprintf( __( 'Daily Archives: %s', 'the7mk2' ), '<span>' . get_the_date() . '</span>' );

        } elseif ( is_month() ) {
            $title = sprintf( __( 'Monthly Archives: %s', 'the7mk2' ), '<span>' . get_the_date( 'F Y' ) . '</span>' );

        } elseif ( is_year() ) {
            $title = sprintf( __( 'Yearly Archives: %s', 'the7mk2' ), '<span>' . get_the_date( 'Y' ) . '</span>' );

        } else {
            $title = __( 'Archives:', 'the7mk2' );

        }

    } elseif ( is_404() ) {
        $title = __( 'Page not found', 'the7mk2' );

    } else {
        $title = __( 'Blog', 'the7mk2' );

    }

    return apply_filters( 'presscore_get_page_title', $title );
}

I have some dynamical pages create using a plugin that query a db and put results in a dynamically generated page: every page is generated on call, so not stored in the db.

Now all pages get title from default page where the shortcode is inserted. I need to dynamically change the title depending on the the generated page.

I've tried to put this function, but it doesn't affect anything:

function presscore_get_page_title() {
    $title = '';

    if ( is_page() || is_single() ) {
        $title = get_the_title();

    } else if ( is_search() ) {
        $title = sprintf( __( 'Search Results for: %s', 'the7mk2' ), '<span>' . get_search_query() . '</span>' );

    } else if ( is_archive() ) {

        if ( is_category() ) {
            $title = sprintf( __( 'Category Archives: %s', 'the7mk2' ), '<span>' . single_cat_title( '', false ) . '</span>' );

        } elseif ( is_tag() ) {
            $title = sprintf( __( 'Tag Archives: %s', 'the7mk2' ), '<span>' . single_tag_title( '', false ) . '</span>' );

        } elseif ( is_author() ) {
            the_post();
            $title = sprintf( __( 'Author Archives: %s', 'the7mk2' ), '<span class="vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( "ID" ) ) ) . '" title="' . esc_attr( get_the_author() ) . '" rel="me">' . get_the_author() . '</a></span>' );
            rewind_posts();

        } elseif ( is_day() ) {
            $title = sprintf( __( 'Daily Archives: %s', 'the7mk2' ), '<span>' . get_the_date() . '</span>' );

        } elseif ( is_month() ) {
            $title = sprintf( __( 'Monthly Archives: %s', 'the7mk2' ), '<span>' . get_the_date( 'F Y' ) . '</span>' );

        } elseif ( is_year() ) {
            $title = sprintf( __( 'Yearly Archives: %s', 'the7mk2' ), '<span>' . get_the_date( 'Y' ) . '</span>' );

        } else {
            $title = __( 'Archives:', 'the7mk2' );

        }

    } elseif ( is_404() ) {
        $title = __( 'Page not found', 'the7mk2' );

    } elseif(  is_page_template( 'accomodations.php' ) ){
    $title = __( 'Test', 'the7mk2' );
}   else {
        $title = __( 'Blog', 'the7mk2' );

    }

    return apply_filters( 'presscore_get_page_title', $title );
}

any suggestion please?

3

The original function ends with this line:

return apply_filters( 'presscore_get_page_title', $title );

That's your cue. You can build a filter that completely overrules the $title generated by that function. Like this:

add_filter ('presscore_get_page_title','wpse263380_presscore_get_page_title',10,1);
function wpse263380_presscore_get_page_title ( $title ) {
  $title = 'My awesome title';
  return $title;
  }
  • Thanks! if I use the function suggested by you it works, but I need an additional part of code to identify the right page to be overrided, so I modified it like this: ' add_filter ('presscore_get_page_title','wpse263380_presscore_get_page_title',10,1); function wpse263380_presscore_get_page_title ( $title ) { if( is_page_template( 'accomodations.php' ) ){ $title = __( 'Test', 'the7mk2' ); } return $title; } ' – Monica Maria Crapanzano Apr 12 '17 at 16:29
  • Thanks, solved! I used the id of the page that works as template instead of is_page_template :) thanks a lot! – Monica Maria Crapanzano Apr 12 '17 at 16:59
  • @pat-j here the second part of my request: wordpress.stackexchange.com/questions/263510/… could you help me please? thanks :) – Monica Maria Crapanzano Apr 13 '17 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.