Last active
September 23, 2024 10:47
-
-
Save atomjoy/de35ec0d73f471813096405fd86724a3 to your computer and use it in GitHub Desktop.
How to dynamically change your site title in WordPress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Overwrite title | |
add_filter('wp_title', 'change_title', 100); | |
function change_title($title) { | |
global $post; | |
if (is_home()) { | |
bloginfo('name'); | |
} else if (is_category()) { | |
single_cat_title(); | |
echo ' ' . __('Category') . ' | '; | |
bloginfo('name'); | |
} else if (is_single()) { | |
single_post_title(); | |
} else if (is_page()) { | |
bloginfo('name'); | |
echo ' | '; | |
single_post_title(); | |
} else if (is_author()) { | |
bloginfo('name'); | |
echo ' | '; | |
echo get_the_author(); | |
} else if (is_tag()) { | |
bloginfo('name'); | |
echo ' | Tag #'; | |
echo single_tag_title('', false); | |
} else if (is_day() || is_month() | is_year()) { | |
if (is_day()) { | |
echo __('Archives') . ' ' . get_the_date(); | |
echo ' | '; | |
bloginfo('name'); | |
} else if (is_month()) { | |
echo __('Archives') . ' ' . get_the_date('F Y'); | |
echo ' | '; | |
bloginfo('name'); | |
} else if (is_year()) { | |
echo __('Archives') . ' ' . get_the_date('Y'); | |
echo ' | '; | |
bloginfo('name'); | |
} else { | |
echo __('Archives'); | |
echo ' | '; | |
bloginfo('name'); | |
} | |
} else { | |
bloginfo('name'); | |
} | |
} | |
// Title | |
// add_theme_support('title-tag'); | |
// Remove | |
// remove_action('wp_head', '_wp_render_title_tag', 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="pl"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title><?php wp_title(); ?></title> | |
<meta name="description" content="<?php echo bloginfo('description'); ?>"> | |
<!-- Favicon --> | |
<link rel="apple-touch-icon" sizes="57x57" href="<?php bloginfo('template_url'); ?>/favicon/apple-icon-57x57.png" /> | |
<link rel="apple-touch-icon" sizes="60x60" href="<?php bloginfo('template_url'); ?>/favicon/apple-icon-60x60.png" /> | |
<link rel="apple-touch-icon" sizes="72x72" href="<?php bloginfo('template_url'); ?>/favicon/apple-icon-72x72.png" /> | |
<link rel="apple-touch-icon" sizes="76x76" href="<?php bloginfo('template_url'); ?>/favicon/apple-icon-76x76.png" /> | |
<link rel="apple-touch-icon" sizes="114x114" href="<?php bloginfo('template_url'); ?>/favicon/apple-icon-114x114.png" /> | |
<link rel="apple-touch-icon" sizes="120x120" href="<?php bloginfo('template_url'); ?>/favicon/apple-icon-120x120.png" /> | |
<link rel="apple-touch-icon" sizes="144x144" href="<?php bloginfo('template_url'); ?>/favicon/apple-icon-144x144.png" /> | |
<link rel="apple-touch-icon" sizes="152x152" href="<?php bloginfo('template_url'); ?>/favicon/apple-icon-152x152.png" /> | |
<link rel="apple-touch-icon" sizes="180x180" href="<?php bloginfo('template_url'); ?>/favicon/apple-icon-180x180.png" /> | |
<link rel="icon" type="image/png" sizes="192x192" href="<?php bloginfo('template_url'); ?>/favicon/android-icon-192x192.png" /> | |
<link rel="icon" type="image/png" sizes="32x32" href="<?php bloginfo('template_url'); ?>/favicon/favicon-32x32.png" /> | |
<link rel="icon" type="image/png" sizes="96x96" href="<?php bloginfo('template_url'); ?>/favicon/favicon-96x96.png" /> | |
<link rel="icon" type="image/png" sizes="16x16" href="<?php bloginfo('template_url'); ?>/favicon/favicon-16x16.png" /> | |
<link rel="shortcut icon" href="<?php bloginfo('template_url'); ?>/favicon/favicon.ico" type="image/x-icon" /> | |
<link rel="icon" href="<?php bloginfo('template_url'); ?>/favicon/favicon.ico" type="image/x-icon" /> | |
<!-- Css, links --> | |
<link rel="preconnect" href="https://fonts.googleapis.com"> | |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | |
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:[email protected]&family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=VT323&display=swap" rel="stylesheet"> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" /> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer" /> | |
<?php wp_head() ?> | |
<!-- Highligt.js --> | |
<link rel="stylesheet" href="https://unpkg.com/@highlightjs/[email protected]/styles/github.min.css"> | |
<script src="https://unpkg.com/@highlightjs/[email protected]/highlight.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/highlightjs-line-numbers.js/dist/highlightjs-line-numbers.min.js"></script> | |
<script type="text/javascript"> | |
hljs.highlightAll(); | |
hljs.initLineNumbersOnLoad({ | |
startFrom: 1 | |
}); | |
function decodeHtml(html) { | |
var txt = document.createElement("textarea"); | |
txt.innerHTML = html; | |
return txt.value; | |
} | |
</script> | |
<style> | |
pre { | |
margin-top: 0px; | |
margin-bottom: 10px; | |
} | |
code, | |
code.hljs { | |
padding: 5px !important; | |
overflow: hidden !important; | |
} | |
/* for block of numbers */ | |
.hljs-ln { | |
float: left; | |
width: 100%; | |
font-size: 14px; | |
font-family: 'JetBrains Mono', 'Fira Code', sans-serif; | |
} | |
.hljs-ln tbody { | |
float: left; | |
width: 100% !important; | |
border: 1px solid #00339911; | |
} | |
.hljs-ln tbody tr { | |
display: flex-table; | |
border-bottom: 1px solid #00339911; | |
} | |
.hljs-ln-numbers { | |
-webkit-touch-callout: none; | |
-webkit-user-select: none; | |
-khtml-user-select: none; | |
-moz-user-select: none; | |
-ms-user-select: none; | |
user-select: none; | |
text-align: center; | |
color: #6885ba; | |
border-right: 1px solid #ff2233aa; | |
vertical-align: top; | |
padding: 5px 10px !important; | |
/* your custom style here */ | |
/*min-width: 60px;*/ | |
} | |
/* for block of code */ | |
.hljs-ln-code { | |
width: 100% !important; | |
padding-left: 20px !important; | |
line-height: 24px; | |
} | |
</style> | |
</head> | |
<body id="body"> | |
<?php get_template_part('include/section', 'top-menu'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment