How to remove « from wordpress several section - wordpress

while writing wp_title(), next_post_link() and previous_post_link() a special character comes, i.e. "«". How to get rid of this character?

wp_title
You can use something like <title><?php wp_title(''); ?></title> to remove the separator.
previous_post_link
If you need to remove the «, you can just simply override it like this
<?php previous_post_link('%link'); ?>
next_post_link
If you need to remove the », you can just simply override it like this
<?php next_post_link('%link'); ?>

Related

template management with wordpress (underscore boilerplate)

I am using underscore to develop a wordpress theme.
I have a custom post type name project, thus I have, for instance, this url: http://a.site.local/projects/a-beauty/.
I have in my template-parts/ directory the file content-projects.
$ cat template-parts/content-projects.php
<h1>Project</h1>
When I browse http://a.site.local/projects/a-beauty/, I have my title but also the sidebar and the footer (even if they do not appear in my content-project.php nor in index.php).
Where are those widgets coming from / loaded ?
Add conditions to the header, footer and sidebar.
For whole custom post archive:
<?php if( !is_post_type_archive( 'project' ) ) : ?>
// wrap the code you don't want to show on that archive
<?php endif; ?>
For custom post only:
<?php if( !is_singular( 'project' ) ) : ?>
// wrap the code you don't want to show on the post
<?php endif; ?>
If you want to put the code you WANT to show, remove the '!' before condition.
P.S.
You can put the whole content in a condition, but keep the
</div><!-- #page -->
<?php wp_footer(); ?>
</body>
</html>
otherwise the page will break :)
Please share some more code from your project so we can easy to understand the real problem.

How to add css class to approved comment

In my theme, I use wp_list_comments() to display comments, I want to add a css class to new approved comment, I have tried to find a filter or something like this but couldn't find anything. Does anyone has a solution to do it, I don't want to edit in wp-includes/comment-template.php. Thank a lot!
You Will Find Code Into wp-includes/comment-template.php
Into Line 1997
<div class="comment-content">
<?php comment_text(); ?>
</div><!-- .comment-content -->
Add Your Custom HTML Here
<?php
ob_start();
comment_form();
echo str_replace('class="comment-form"','class="comment-form your-custom-class"',ob_get_clean());
?>
Now the standard class comment-form will be replaced by itself plus the custom class.

wp_title showing page title but not site title

I couldn't find an answer to this question anywhere and I have a hard time believing I'm the only one who has had this problem.
My title function inside my title tag of header.php, <?php wp_title('|', true, 'right'); ?>, is returning the page title but not the site title.
Example: About Us |
Why would it not be returning the site name??
Looks like wp_title() does not return the site's title. Sorry, hopefully someone will benefit from this answer.
I've never tried combining the entire title inside one function. Instead I use multiple calls:
<?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' |'; } ?> <?php bloginfo('name'); ?>

Get, modify, then print post title in wordpress

Is there a way native way in wordpress to make uppercase the first letter of the first word of the scentence / the_title of the post?
If not, how do I do it in php, while it is wrapped in a <a></a> tag?
Here is the full line of code.
<?php ucfirst(the_title());?>
As you see, I have tried ucfirst, but it does not work. The other thing that I tried is:
<?php
$temp_title = the_title();
$final_title = ucfirst($temp_title);
?>
<?php echo $final_title;?>
ucfirst() returns a string. You need to echo the value returned from ucfirst().
Furthermore, the WordPress function the_title() prints the title directly, rather than returning it as a string. Use get_the_title() instead.
<?php echo ucfirst(get_the_title());?>
I think this is your problem: http://core.trac.wordpress.org/browser/tags/3.8/src/wp-includes/post-template.php#L51. As you can see the_title() is using get_the_title() and then if($echo) it echoes it out. I would experiment and try get_the_title().
First off you had an ending parantheses that didn't have a matching parantheses in your echo $final_title. Second you should try to apply ucfirst to the echo of your title. I removed $finaltitle, because it no longer serves a purpose. I haven't tried the code, but it should work. Please note that ucfirst() only works if the first letter is in the alphabet.
<?php
$temp_title = the_title();
?>
<?php echo ucfirst($temp_title);?>

Home Page Only Footer

I have a blog, http://sweatingthebigstuff.com and I would like to add an extra line in the footer which will display only from the homepage. I found this code, but it is not working for me. Do I have the wrong syntax or is there something else I can try to get this to work?
<?php if ( is_home() ) { ?>
text
<?php } ?>
Here is where footer.php is called
<?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
<div class="cleared"></div>
<?php get_footer(); ?>
And here is the footer code:
text 2
Contact | Disclaimer | Privacy StatementCopyright © 2009-2010 Sweating The Big Stuff. All Rights Reserved.
and then some sitemeter crap.
is_home() sets a global var that doesn't seem to reset itself or re-evaluate, wp kinda strange.
Try putting wp_reset_query() at the end start of your if statement code
Actually, it'll be better to call it before as we can ensure the queries are reset
<?php wp_reset_query();
if ( is_home() ) { ?>
text
<?php } ?>
Now that the php is working, ideally you'd want the code above.
text
I just did a view source and I can plainly see the php code, which shouldn't be visible since it is meant to be parsed server side. The following shouldn't be there in the view source.... wrong file being edited?
<p>
<?php if ( is_home() ) { ?>
text
<?php } ?>
<wp_reset_query()>
<br />
<br />
The footer.php file should be located in wp-content/themes/nameofyourtheme folder
is_home() is a method that should return true or false. You need to implement this method somewhere. If blogspot doesn't implement this method for you, you need to do it yourself. For your website I think this function would do what you want:
<?php
function is_home(){
$r = $_SERVER['REQUEST_URI'];
return $r == '/' || $r == '' || $r == '/index.php';
}
if(is_home()) {
?>
text
<?php } ?>
And where you want the footer, put:
<?php include 'footer.php'; ?>
instead of the line:
<?php get_footer(); ?>
I believe your problem is that get_footer() is reading the footer as text, so it isn't executing the PHP beforehand. If you do it this way you can add as much PHP in the header as you want.
There is nothing wrong with your syntax, and when I view your page source, I see " text "
What is the file extension of your footer page? if it is "footer.php" then I shouldn't see the opening and closing terms for php (). php won't run unless the file extension is ".php"
as to a previous answer:
<?php wp_reset_query();?> should go BEFORE <?php if(is_home()){?>text<?php } ?> in this scenario. is_home() depends on a loop being present on the page. Maybe somewhere you used a custom query, or one of your plugins used a custom query that upset the default query vars. Like I said, use the reset statement before your if statement.
You need to modify the code to include a check for is_front_page() like so:
<?php
$ishomepage = ( is_home() || is_front_page() );
switch( $ishomepage )
{
case true :
echo 'Your homepage-only snippet of text goes here';
break;
case false :
default :
// Do nothing... or do something else...
break;
}
?>
Reference: WordPress Codex: is_front_page()
Default WP installations don't have a homepage defined, it uses your index.php and checks for other templates like a home.php template as a starting point (home.php only if your theme has it.) Here's a diagram from their online docs that shows how their hierarchy works: WordPress Template Hierarchy.
By default, WordPress shows your most recent posts on the front page
of your site. But many WordPress users want to have a static front
page or splash page as the front page instead. This "static front
page" look is common for those who wish to not have a "blog" look to
their site, giving it a more CMS (content management system) feel.
If you want to know how to set a static homepage, read this article and follow the instructions: Creating a Static Frontpage. When you set a static front page, is_home() will work as expected.

Resources