Hide wp_head () only in the homepage - php

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 ?

Related

Wordpress and PHP includes

If I was looking to use my own HTML for a certain page on my wordpress theme, how can I go about it?
Please advise where code should go
If I can use raw HTML or PHP INCLUDES.
If you are looking to place the HTML in the main page content, just use the text editor of WordPress(http://www.wpbeginner.com/glossary/text-editor/). The header & footer would be modified inside the header.php and footer.php files of your theme. the directory where these would be located should be /wp-content/themes/salient/. If you want the header and footer to only be modified only on specific pages, you will want to use the is_page() function built into WordPress(https://codex.wordpress.org/Function_Reference/is_page).
Example of limiting header or footer modification to specific page:
<?php if( is_page( 42 ) !== false ) { ?>
<!-- HTML that should only appear on page with id of 42. -->
<?php } ?>

Customizing a WordPress Template to Remove *One* Page Title

I'm using WordPress to build a simple personal website. I know (basic) HTML and CSS but no PHP, so I'm having a little trouble with a particular customization.
My theme inserts the title of the page at the top of the page. I would like to stop it from doing this on one page only (the home page).
Thanks for any help. The site is here: http://www.melvingauci.com/
Try going into your page.php template and remove <?php the_title(); ?>. Then add this:
<?php if ( ! is_front_page() ) { ?>
<?php the_title(); ?>
<?php } ?>
Note: This assumes your home page uses the page.php template. If another template is used, then the same approach will work.

WordPress conditional statement for front-page or inner page

I need help with the templating in wordpress.
On the front-page I want a custom static header, while all the other pages should use the title for their page instead.
Also, if the page is not the front-page I want to add some custom HTML next to the title.
What is the best way to do this?
You can do it like this, including the following in header.php (I've just added some example content);
<?php
if ( is_front_page() ) {
echo '<div id="homestuff">Home stuff in here</div>';
} elseif (is_page()) {
echo '<div id="pagestuff">'. the_title() .'</div>';
}
?>
Take note, there is also a is_home() in Wordpress and it's sometimes easy to get in a bit of a tangle about whether is_front_page() or is_home() is the correct one to use, this stackexchange answer is a good source of info about that;
Whether to use is_front_page() or is_home() in Wordpress

wordpress: Conditionally run javascript and load image for post pages

I have a javascript curl effect in place which loads an image and javascript file for the curl effect. But I want to appear in the post pages only.
So I want to do:
if this is a postpage{
load image;
load javascript;}
What is the way to do this in wordpress with php?
If you want to add it only to posts pages and homepages and your plug ins are troubling you..you might want to try
<?php if (is_single()|| is_home() || is_page()){ ?>
load image;
load js;
<?php } ?>
if you want it for only posts and pages, try
<?php if (is_single()|| is_page()){ ?>
load image;
load js;
<?php } ?>
not entierly sure what your after,
but you say you have the code ont he index.php page,
again un-sure has to, how you have this setup,
but if its only to be shown on a post or page or a postpage? (single post),
would be better to move your code into the header.php file? or have it only in the single.php file which means its only loaded when viewing a single post,
in turn it wont be shown on any other pages, except the single (full post) page..
then using the likes
if( is_single() ){
//then show - run your code?
}
?
Marty
Edit:
for both posts & pages then use
if( is_single() || is_page() ){
//then show - run your code?
}
this will only show your code when its a single post OR within a page.

How can I tell my wordpress to do something in the header if its a blog page?

In a previous post (Don't show this if the url contains the following) I asked how I would go about having my header echo a div if the user loaded a URL with /blog in the header.
What I didn't take into consideration, was that I don't want the div to display if its not just got /blog in the url, but if its any blog post, not just the index page of the blogs.
How do I run a bit of code from my header.php if the page I'm looking at is a blog post?
You would use the Wordpress functions is_single() and is_page.
if(!is_single() && !is_page() && !is_home() && !is_archive())
{
/* This will not display for any post, page, the home page, or an archive.
You can remove each is statement according to your needs */
}
For only posts, only use is_single, the same for page, home, and archive.
The full listing of is_statements can be found here. Here are some others:
is_home() : Home Page
is_front_page : Front Page
is_single() : Single Post
is_admin() : Admin Panel
is_sticky() : Sticky Post
is_page() : Page
is_category
is_tag
is_author
It's been long since I've played with wordpress but you can achieve a lot with using the conditional tags:
http://codex.wordpress.org/Conditional_Tags
Seems like is_single() might do what you want. Eg:
if (!is_single())
{
// display div
}

Categories