{"id":4097,"date":"2023-09-13T10:01:53","date_gmt":"2023-09-13T08:01:53","guid":{"rendered":"https:\/\/www.knowboard.de\/?p=4097"},"modified":"2023-09-13T10:05:03","modified_gmt":"2023-09-13T08:05:03","slug":"changing-the-page-title-in-wordpress","status":"publish","type":"post","link":"https:\/\/www.knowboard.de\/changing-the-page-title-in-wordpress\/","title":{"rendered":"Changing the page title in WordPress"},"content":{"rendered":"\n
\/\/CHANGE POST TITLE\nfunction custom_modify_title( $title, $id = null ) {\n return 'CUSTOM '.$title;\n }\nadd_filter( 'wp_title', 'custom_modify_title', 10, 2 );\nadd_filter( 'the_title', 'custom_modify_title', 10, 2 );<\/code><\/pre>\n\n\n\nChange depending on post type<\/p>\n\n\n\n
\/\/CHANGE POST TITLE\nadd_filter('the_title','custom_modify_title2');\nfunction custom_modify_title2($data){\n global $post;\n\n if (get_post_type( $post->ID ) == \"expertenprofil\") {\n return get_post_meta($post->ID, 'wpcf-anonymer-titel', true);\n } else {\n return;\n }\n}<\/code><\/pre>\n\n\n\nChanging document title<\/p>\n\n\n\n
\/\/CHANGE POST TITLE\nadd_filter( 'pre_get_document_title', 'change_profile_title' );\nfunction change_profile_title () {\n\tglobal $post;\n\n\tif (get_post_type( $post->ID ) == \"expertenprofil\") {\n\t\treturn get_post_meta($post->ID, 'wpcf-anonymer-titel', true);\n\n\t} else if (get_post_type( $post->ID ) == \"bewertung\") {\n\n\t\t\/\/bewertung nutzt sowieso anonymen titel daher brauche ich das nicht\n\t\t\/\/ get the id of the post\n\t\t\/*\n\t\t$the_id = $post->ID;\n\t\t\/\/ get the custom taxonomy term name\n\t\t$source_archive_name = wp_strip_all_tags( get_the_term_list( $the_id, 'bundesland', '', ' \/ ' ) );\n\t\t\/\/ read all the data for the term into an array\n\t\t$term_data = get_term_by( 'name', $source_archive_name, 'bundesland', ARRAY_A );\n\t\t\/\/ pull the term id out of the array\n\t\t$term = get_term( $term_data[\"term_id\"], 'bundesland' );\n\t\t$bundesland = $term->name;\n\t\treturn \"Einigungsstelle in \". $bundesland;\t\n\t\t*\/\n\t\t\/\/return $post->post_title;\n\t\treturn;\n\n\t} else {\n\t\treturn;\n\t}\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"Change depending on post type Changing document title<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[1,56,79,6],"tags":[],"class_list":["post-4097","post","type-post","status-publish","format-standard","hentry","category-allgemein","category-php","category-snippet","category-wordpress","entry","no-media"],"_links":{"self":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/4097"}],"collection":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/comments?post=4097"}],"version-history":[{"count":4,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/4097\/revisions"}],"predecessor-version":[{"id":4105,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/posts\/4097\/revisions\/4105"}],"wp:attachment":[{"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/media?parent=4097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/categories?post=4097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.knowboard.de\/wp-json\/wp\/v2\/tags?post=4097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}