{"id":2945,"date":"2018-12-20T16:23:39","date_gmt":"2018-12-20T14:23:39","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=2945"},"modified":"2018-12-21T12:43:41","modified_gmt":"2018-12-21T10:43:41","slug":"wordpress-shortcode-date","status":"publish","type":"post","link":"https:\/\/www.extradrm.com\/?p=2945","title":{"rendered":"WordPress : Modify Title post with a dynamic tag for better SEO experience"},"content":{"rendered":"\n<p>Let us say that you want to display events every month with changing title post for your calendar to current month (see <a href=\"http:\/\/www.salsarock.com\/agenda\/soirees\">http:\/\/www.salsarock.com\/agenda\/soirees)<\/a><\/p>\n\n\n\n<p>In wp-include\/general-template.php Modify your function _wp_render_title_tag to display the calculated dynamic string to add in your title page or post.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * Displays title tag with content.\n *\n * @ignore\n * @since 4.1.0\n * @since 4.4.0 Improved title output replaced `wp_title()`.\n * @access private\n *\/\nfunction _wp_render_title_tag() {\n\tif ( ! current_theme_supports( 'title-tag' ) ) {\n\t\treturn;\n\t}\n global $post;\n\t\/\/$year = date(\"Y\");\n\t\/\/$month = date(\"F\");\n\t$madate = date_i18n(\"F Y\");\n\t$str = 'Soir\u00e9es Salsa \u00e0 Paris en ' . $madate;\n\t$postid = get_the_ID();\n\t\n\tif ( $postid == 121 ) {\n\t    echo '&lt;title>' . $str . '&lt;\/title>' . \"\\n\";\n\t\t\n\t}\n\telse {\n  echo '&lt;title>' . wp_get_document_title()  . '&lt;\/title>' . \"\\n\";\n   }\n}<\/code><\/pre>\n\n\n\n<p>In the functions.php of your theme add those functions to change the tag <strong>salsadanse<\/strong> to show the current month :<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \/\/* Activate shortcode function in Post Title\n\nadd_filter( 'the_title', 'do_shortcode' );\n\n\n\nadd_shortcode( 'salsadanse' , 'current_year' );\n    \n\nfunction current_year() {\n\t\n\t$salsadanse = date_i18n(\"F Y\");\n    return \"$salsadanse\";\n}   \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Let us say that you want to display events every month with changing title post for your calendar to current month (see http:\/\/www.salsarock.com\/agenda\/soirees) In wp-include\/general-template.php Modify your function _wp_render_title_tag to display the calculated dynamic&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2842,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31,6],"tags":[],"youtube_video":null,"_links":{"self":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2945"}],"collection":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2945"}],"version-history":[{"count":0,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2945\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/media\/2842"}],"wp:attachment":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}