Guys I'm having an issue with the home page title of my wordpress blog after i updated the wordpress to 4.4. I'm not sure if its because of the update. The issue is, I'm getting "Home" prefix for the home page title. Here's my website - www.autodevot.com
In the wordpress Settings > General, in the Site Title section, I've written Autodevot. And in the Tagline section, I've written Automotive World News | Car News and Reviews | Upcoming Cars in India. So earlier, this tagline section was appearing in the home page title. Now for some reason, Its adding "Home" prefix for the home page title. So now the title comes as Home - Autodevot. I need to get rid of that "Home" and want the tagline section to appear in the title like before. Title for rest of the pages are appearing fine. Problem is only with the home page title. I opened the header.php and the code is like this
<?php
if ( ! function_exists( '_wp_render_title_tag' ) ) {
function theme_slug_render_title() {
?>
<title><?php wp_title( '|', true, 'right' ); ?></title>
<?php
}
add_action( 'wp_head', 'theme_slug_render_title' );
}
?>
Any help?
Many sources on this topic points to eithe using a plugin or changing some PHP code. However, a newer feature (WordPress 4.7) allows adding custom CSS to a theme (which is bound to that theme, but is not overwritten at theme updates). This saves the need to create a child theme. This tool is accessed through the "Additional CSS" tab in theme customization.
Taking inspiration from this blog post about how to select the page title in CSS, I've added:
.home .entry-title {display: none;}
to hide the h1 title "Home" on my home page. I suspect that the home class is generic for all front pages (no matter the actual title of the home page).
As an alternative, to remove the title on all pages (but not blog posts):
.page .entry-title {display: none;}
Finally, as explained in the blog post, it is possible to target a specific page with its id:
.page-id-177 .entry-title {display: none;}
where page-id-177 comes from the class attribute of the <body> tag of the page of interest.
Thanks to the live preview, it's easy to see if the CSS is effective!
replace your code with this code
<?php
if ( ! function_exists( '_wp_render_title_tag' ) && !is_home() || !is_front_page() ) {
function theme_slug_render_title() {
?>
<title><?php wp_title( '|', true, 'right' ); ?></title>
<?php
}
add_action( 'wp_head', 'theme_slug_render_title' );
}
?>
You can try this one, Just add your theme functions.php
add_filter('wp_title', 'filter_pagetitle');
function filter_pagetitle($title) {
global $wp_query;
if (is_front_page()){
return $wp_query->post->post_title;
}
}
just change the file name as one of your keyword. For wordpress, change the page title to your keywords.
I did it and works fine now.
Related
I've this code in the header Homepage that find automatically the title page for homepage and the posts how title tag. But I've my personal title tag only in the home page. The source code show 2 title tag in the home.
How can I hide this code in the home?
<? php wp_head(); ? >
i think, you can use the "is_home()" and "is_frontpage()" function, depending on how your frontpage is setted up in theme (static page, blog page...), one of them or using logical and can be necessary.
with this you can do like:
<?php
if( !is_home() && !is_frontpage() ) {
wp_head();
} else {
// custom head code
}
?>
an other way is using a separate template for home/frontpage (using a frontpage.php/home.php), where you put in your code.
here the difficult for me was to learn how wordpress is using more specific templates and templateparts (like using get_header('home') to use header-home.php instead of header) and with which weight-order they are used.
https://developer.wordpress.org/reference/functions/is_home/
https://codex.wordpress.org/Creating_a_Static_Front_Page
is_front_page() & is_home() can't help you ?
I am trying to design a wordpress theme that has a problem with admin bar. If I select "don't show user bar" it's working properly. But when I want to see admin bar in the top, the themes looks like picture I attached. I couldn't see my logo its accurate size.
you could customize the admin bar layout by making it almost transparent in order to see what lies beneath it. This can be accomplished by overriding the default admin bar style used by WordPress so to make it 30% opacity and fully visible only on hover:
function my_theme_setup() {
add_theme_support( 'admin-bar', array( 'callback' => 'my_admin_bar_style') );
}
add_action( 'after_setup_theme', 'my_theme_setup' );
function my_admin_bar_style() {
?>
<style>
#wpadminbar {position:fixed;opacity:0.3;}
#wpadminbar:hover {opacity:1;}
</style>
<?php
}
Using WordPress. My header navigation includes pages that link to categories. For instance, the 'about' in the header navigation is a page but it links to a category called 'about'. On this page, I have the page title displaying and then the post with the 'about' category is also displayed on this page.
When I try to remove the page title ('About') it removes that title AND the post's title on that page.
Ex. I am able to modify the pages with: (.category-21 is the ID for the about page)
.category-21,
.category-22,
.category-23 {
color: blue;
}
But when I try to remove the page title with:
.category-21 h2,
.category-22 h2,
.category-23 h2 {
display: none;
}
It removes the page title AND the post's title.
The problem is that the header 2 modifies both titles.
How do I separate the two?
What would I add/modify to functions.php (or single.php?) and to style.css?
I'm also using this to exclude posts with the category of 'about' (and two others):
function excludeCat($query) {
if ( $query->is_home ) {
$query->set('cat', '-21, -22, -23');
}
return $query;
}
add_filter('pre_get_posts', 'excludeCat');
I think it's also excluding these categories from certain style changes in style.css (if that helps).
.category-23 h2:nth-child(2)
OR
.category-23 h2:last-child
OR
Add a class to another h2 and then change the style of it.
I used wp-types toolset to create a custom post type and a post relationship to pages; there is now a Post Relationships section at the bottom of every page edit screen. The problem is, I would only like this section to show up on a couple of pages.
Is there something I can add to functions.php (or another alternative) to hide this section from all page edit screens expect for those particular ones.
The section div id that I want to hide is #wpcf-post-relationship and the data post id of the pages that I would like it to be visible are 143 and 23.
-- (update) --
As admin_init is triggered before any other hook when a user access
the admin area, we finally use instead admin_head because action is
just triggered inside the <head> of the admin page (thanks to John).
The easy way is to use a simple CSS rule with the 'admin_head' hook, to do it, like this:
1) create a css file named hide_some_field.css and put it into your active child theme folder, with this code:
#wpcf-post-relationship {
display:none;
}
2) Add this code in your active child theme functions.php file:
add_action('admin_head', 'ts_hiding_some_fields');
function ts_hiding_some_fields(){
// your 2 pages in this array
$arr = array(23, 143);
if(get_post_type() == 'page' && !in_array(get_the_ID(), $arr))
{
wp_enqueue_style( 'hide_some_field', get_stylesheet_directory_uri().'/hide_some_field.css');
}
}
If you use a theme instead, change:
get_stylesheet_directory_uri() by get_template_directory_uri().
Another similar alternative (without an external CSS file) is:
add_action('admin_head', 'ts_hiding_some_fields');
function ts_hiding_some_fields(){
// your 2 pages in this array
$arr = array(23, 143);
if(get_post_type() == 'page' && !in_array(get_the_ID(), $arr))
{
echo '<style type="text/css">
#wpcf-post-relationship {display: none;}
</style>';
}
}
I have a theme that I am developing using the _s (aka: underscores) theme.
I do not want my archives to include the sidebar.php file.
My archive.php and paged.php files do not have the sidebar.php
included.
I created a home.php file which includes the get_sidebar()
function, and edited my index.php to not include that function.
I'm still seeing my sidebar when I click "Older Posts" on my site which brings me to: MYDOMAIN/?paged=2 -- this is not what I want.
Specific archive pages (such as for months and categories) do not display the sidebar, which is what I want.
I only want the sidebar to appear on the front page of the site.
I checked the body tags on my home page and on the paged "Older Posts" archive pages to determine what template is being rendered.
Home page:
<body class="home blog">
paged "Older Posts" archive page:
<body class="home blog paged paged-2">
This leads me to believe they are both using the home.php template. How can I get those pages to use a different template?
What am I doing wrong?
A friend helped me resolve this issue and I thought I'd share our solution. In order to make sure the sidebar appeared only on the front page of the blog and not appear on the ?paged= pages, we added some conditional statements around the call to the sidebar on home.php:
<?php if ( !is_paged() ) { ?>
<?php get_sidebar(); ?>
<?php } ?>
Additionally, this code could be added to the sidebar to keep it from appearing on other pages such as category pages, single posts, etc. While this wasn't necessary since I had used specific templates for those pages that did not include the sidebar, here it is in case it's useful for others:
<?php if ( is_front_page() ) { ?>
<!-- ALL CODE FOR YOUR SIDEBAR HERE -->
<?php } ?>