How to remove meta noindex from search urls on wordpress? - php

I am looking to index my search URLs on Google for SEO ranking. In order for me to do that I need to remove <meta name="robots" content="follow, noindex"/> and replace it with <meta name="robots" content="follow, index"/>
Sample url
https://seosly.com/?s=audit
I am currently using rank math SEO plugin, Tried installing Yoast as well but couldn't find any option there. Given below is my code for search.php file maybe if we can do something from here?
/**
* The template for displaying search results pages.
*/
$mts_options = get_option(MTS_THEME_NAME);
get_header(); ?>
<div id="page">
<div class="article <?php mts_article_class(); ?>">
<div id="content_box">
<h1 class="postsby">
<span><?php _e("Search Results for:", 'myblog' ); ?></span> <?php the_search_query(); ?>
</h1>
<?php $j = 0; if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="latestPost excerpt <?php echo (++$j % 3 == 0) ? 'last' : ''; ?>">
<?php mts_archive_post(); ?>
</article><!--.post excerpt-->
<?php endwhile; else: ?>
<div class="no-results">
<h2><?php _e('We apologize for any inconvenience, please hit back on your browser or use the search form below.', 'myblog' ); ?></h2>
<?php get_search_form(); ?>
</div><!--noResults-->
<?php endif; ?>
<?php if ( $j !== 0 ) { // No pagination if there is no posts ?>
<?php mts_pagination(); ?>
<?php } ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?> ```

I missed that this was specific to the search results page. WordPress adds a default noindex to that page which you should be able to remove with:
remove_filter( 'wp_robots', 'wp_robots_noindex_search' );

Related

HTML only print once in Wordpress Loop

I have a code chunk that is inside the_content(); I'm using acf repeater as well. So when I post a blog, I'll either use the_content(); or the acf field. I have h2 tag ( latest articles ) that I only want printed one time, but it's printing everytime I make a post.
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<div class="container">
<div class="row">
<div class="col-md-4 sidebar-r">
<?php echo the_content(); ?>
</div><!-- end sidebar-r -->
<?php
$i = $wp_query->post_count;
if($i <=1) {
echo '<h2 class="link-title">
<?php the_sub_field('link_title'); ?>,
</h2>';
}else{
echo '';
}
?>
<div class="col-md-8 links-wrap">
<?php if(have_rows('daily_links')): ?>
<?php while(have_rows('daily_links')): the_row(); ?>
<a href="<?php the_sub_field('link_url'); ?>" target="_blank">
<h2 class="link-title">
<?php the_sub_field('link_title'); ?>,
</h2>
<h3 class="link-source">
<?php the_sub_field('link_source'); ?>
</h3>
</a>
<?php endwhile; ?>
<?php endif; ?>
</div><!-- end links wrap -->
</div><!-- end row -->
</div><!-- end container -->
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
You'll see I tried using php to count the posts and if more than one post, don't print the tag, but couldn't figure out the exact logic and syntax.
I am honestly struggling a bit to understand exactly what you are trying to do and since I do not even have the posts and other key pieces of information so that I can properly replicate your issue so that I can help you better, this is a little bit challenging. That being said, looking into some ideas I came across another stackoverflow question/answer that might be relevant for you in catching the first post and does something to it. The answer to the referenced question instance was this:
<?php if (have_posts()) : $postCount = 1; while (have_posts()) : $postCount++; ?>
<?php if($postCount == 2) { ?>
// SOMETHING TO DO WITH FIRST POST
<?php } else { ?>
// SOMETHING TO DO WITH ALL OTHER POSTS
<?php } ?>
This was suggested by user Bora in this answer from 2013.
Let me know if that helped!

Getting Wordpress to show message when no posts exist in category

I am trying to get my blog to show a message to visitors when they visit the category main page (ex: www.website.com/category-slug-here/), but can't seem to figure out the Wordpress Loop quite right. Here is what I started with in my theme's index.php file:
get_header(); ?>
<div id="page-wrap" class="blog-page blog-fullwidth container">
<div id="content" class="blog-wrap <?php echo esc_attr($sidebarlayout); ?> columns">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( 'framework/inc/post-format/entry', get_post_format() ); ?>
<?php endwhile; endif; ?>
<?php get_template_part( 'framework/inc/nav' ); ?>
</div>
<?php if($sidebar != 'no-sidebar'){ ?>
<div id="sidebar" class="<?php echo esc_attr($sidebarorientation); ?> alt">
<?php get_sidebar(); ?>
</div>
<?php } ?>
</div>
<?php get_footer(); ?>
And here is how I tried to alter it:
get_header(); ?>
<div id="page-wrap" class="blog-page blog-fullwidth container">
<div id="content" class="blog-wrap <?php echo esc_attr($sidebarlayout); ?> columns">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( 'framework/inc/post-format/entry', get_post_format() ); ?>
<?php endwhile; else: ?>
<p>Sorry, looks like this category is empty!</p>
<?php endif; ?>
<?php get_template_part( 'framework/inc/nav' ); ?>
</div>
<?php if($sidebar != 'no-sidebar'){ ?>
<div id="sidebar" class="<?php echo esc_attr($sidebarorientation); ?> alt">
<?php get_sidebar(); ?>
</div>
<?php } ?>
</div>
<?php get_footer(); ?>
However, making this change doesn't seem to yield any results. Am I missing something here? Seems like this should work (but I'm also not a total PHP guru, which is why I came here to consult with the masses). ;)
In wordpress the posts in category are shown in archive.php page .
Try to write the else condition in archive page instead of index.php page

Im trying to kill the sidebars but i cant - wordpress

I am trying to setup a custom page, you can take a look here:
http://dageniusmarketer.com/download-the-book-now
and im using this code for my custom page. The sidebars as far as i can tell have IDs of "navigation", and "sidebar", however, the rules i am applying to them are not working. I tried a test rule with the ID "content", and it works as expected. Why am i not able to hide the sidebars? Something isn't making sense.
<?php
/*
* Template Name: My Custom Page
* Description: A Page Template with No Sidebars.
*/
?>
<?php get_header(); ?>
<!--single.php-->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post">
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php echo get_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
<?php the_title(); ?></a></h2>
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<p class="metadata">
<?php printf(__('%1$s %2$s', 'mtsgossip'), $time_since, get_the_time(__('l, F jS, Y', 'mtsjourney')), get_the_time()); ?>,
<?php _e('by ','mtsjourney');?> <?php the_author();?>
<?php _e('and is filed under','mtsjourney'); ?> "<?php the_category(', ') ?> ".
<?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
// Kommentare und Pingen erlaubt ?>
<?php _e('You can','mtsjourney'); ?> <?php _e('leave a response here','mtsjourney'); ?>,
<?php _e('or send a','mtsjourney'); ?>
<a href="<?php trackback_url(true); ?>" ><?php _e('Trackback','mtsjourney'); ?></a>
<?php _e('from your own site','mtsjourney'); ?>.
<?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
// Nur Pingen erlaubt ?>
<?php _e('Responses are currently closed, but you can send a','mtsjourney'); ?>
<a href="<?php trackback_url(true); ?>" >
<?php _e('Trackback','mtsjourney'); ?></a>
<?php _e('from your own site','mtsjourney'); ?>.
<?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
// Kommentare geschlossen, Pingen erlaubt ?>
<?php _e('You can','mtsjourney'); ?>
<?php _e('leave a response here','mtsjourney'); ?>.
<?php _e('Pinging is currently not allowed','mtsjourney'); ?>.
<?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
// Kommentare und Pings sind nicht erlaubt. ?>
<?php _e('Both comments and pings are currently closed','mtsjourney'); ?>.
<?php } edit_post_link('E','',''); ?>
</p>
</div>
<div id="navigation" style="margin-left:200px;"></div>
<div id="sidebar" style="display:none"></div>
<div id="content" style="width:900px"></div>
<!--postend-->
<p class="navigate">
<?php previous_post_link('« %link') ?>
||
<?php next_post_link(' %link »') ?>
</p>
<?php endwhile; endif;?>
<!--post end-->
<!--single.php end-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Looking at the page structure, I tried to remove left and right sidebar by adding following styles.
Put the following styles as inline css in the desired template, so that it don't affect the layout of any other page. Hope this helps.
div#navigation
{
display:none;
}
div#sidebar
{
display:none;
}
div#content
{
margin: 5px 0 75px 0;
}
Your sidebar is being called with this line:
<?php get_sidebar(); ?>
You can try commenting it out to hide the sidebar:
<?php //get_sidebar(); ?>
You have two divs with the "sidebar" id, the one we can see in the code you posted (Which has the styles) and the one that eventually gets created by <?php get_sidebar(); ?>
These are not the same elements, so to fix your problem just remove that superfluous sidebar and apply the styles in your stylesheet.
Why dont you delete all the content of sidebar.php? so, all other files that call it will show nothing.
your sidebar is being called with this line
<?php get_sidebar(); ?>
try to comment it

Custom Post Meta Search Template

I'm struggling with getting wordpress to search custom post meta from a page template. I've looked all over the internet and can't seem to find anything that will work. No plugins seem to work either.
On my posts, I have the custom meta: "rate" and the value: "10" - Wordpress delivers no result when searching any of these.
I'd be very appreciated if someone could write me a searchpage.php page template or point me in the right direction (I'm not good with php).
Here's my current PHP code:
<?php
/*
Template Name: Search Custom Meta
*/
?>
<?php get_header(); ?>
<div id="content">
<div class="container clearfix fullwidth">
<div id="left-area">
<?php query_posts('meta_value='.$s); ?>
<?php if (!empty($wp_query->posts)) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
</div> <!-- end #left-area -->
</div> <!-- .container -->
</div> <!-- #content -->
<?php get_footer(); ?>
You checking incorrect variable in if so try removing that one,
query_posts('meta_value='.$s);
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;

Wordpress: Infinite Re-direct Loop Error on Custom Theme

I have a set-up a custom theme on my wordpress install. I have been developing with it locally and everything was working fine.
I uploaded to my server tonight and was setting up the fresh wordpress install. I turned on permalinks and all of a sudden my custom category pages are causing infinite re-direct loops.
My .htaccess is writable so I don't think its that problem (I have seen this mentioned a lot online).
The code from one of my custom pages is below - it pulls from a specific category - does anyone know how to fix this issue?
<?php get_header(); ?>
<?php
/*
Template Name: Podcasts
*/
?>
<ul class="mcol">
<?php
query_posts("cat=1");
while(have_posts()) : the_post(); ?>
<li class="article" id="post-<?php the_ID(); ?>">
<?php
if ( has_post_thumbnail() ) { ?>
<?php
$imgsrcparam = array(
'alt' => trim(strip_tags( $post- >post_excerpt )),
'title' => trim(strip_tags( $post->post_title )),
);
$thumbID = get_the_post_thumbnail( $post->ID, array(200,200), $imgsrcparam ); ?>
<div class="preview"><?php echo "$thumbID"; ?><div class="front-titles"><?php the_title(); ?></div></div>
<?php } else {?>
<div class="preview"><img src="<?php bloginfo('template_url'); ?>/images/default-thumbnail.jpg" alt="<?php the_title(); ?>" /></div>
<?php } ?>
<div class="article-over">
</div>
</li> <?php ?>
<?php endwhile;
//Reset Query
wp_reset_query();
?>
</ul>
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php else : ?>
<h1 id="error"><?php _e("Sorry, but you are looking for something that isn’t here."); ?></h1>
<?php endif; ?>
<div class="pagination"><?php previous_posts_link('<< Newer Entries', 0) ?> <?php next_posts_link('Older Entries >>', 0); ?> </div>
<?php get_footer(); ?>
Anyone any ideas? I'm quite new to this so am unsure as to what the problem might be...
What your doing is weird.
query_posts is meant to alter the main loop.
You have 2 loops with different syntax on the same page.
The second loop is not doing anything, so remove it, and use get_posts or WP Query for your custom query.

Categories