Динамически Переопределять Необычный Заголовок


Я пытаюсь переопределить необычный заголовок, созданный с использованием темы 7. 7 заголовков генерируются с помощью этой функции:

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 );
}

У меня есть несколько динамических страниц, созданных с помощью плагина, который запрашивает базу данных и помещает результаты в динамически создаваемую страницу: каждая страница создается по вызову, поэтому не хранится в базе данных.

Теперь все страницы получают заголовок со страницы по умолчанию, на которой вставлен шорткод. Мне нужно динамически изменять заголовок в зависимости от сгенерированного страница.

Я пытался поставить эту функцию, но она ни на что не влияет:

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 );
}

Какие-нибудь предложения, пожалуйста?

Author: cjbj, 2017-04-12

1 answers

Исходная функция заканчивается этой строкой:

return apply_filters( 'presscore_get_page_title', $title );

Это твой намек. Вы можете построить фильтр , который полностью отменяет $title, созданный этой функцией. Вот так:

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;
  }
 4
Author: cjbj, 2017-04-12 13:00:44