I want that wordpress should display title from selected post and selected page.I am using buisness news theme. Is their any setting available or I need to change in code I am new to wordpress. I found title code in header.php
<title><?php
//Print the <title> tag based on what is being viewed.
global $page, $paged;
// Add the blog name.
bloginfo( 'name' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) echo " | $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
echo ' | ' . sprintf( __( 'Page %s', 'business-news' ), max( $paged, $page ) );
?></title>
But when I select particulate post it shows only site name in title. Where I am missing?
Try this:
<title>
<?php single_post_title(); ?>
</title>
manage using add_filter wp_title() function
<title><?php wp_title(''); ?></title>
If u want change using like this in function.php
function theme_name_wp_title( $title, $sep ) {
if ( is_feed() ) {
return $title;
}
global $page, $paged;
// Add the blog name
$title .= get_bloginfo( 'name', 'display' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title .= " $sep $site_description";
}
// Add a page number if necessary:
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
$title .= " $sep " . sprintf( __( 'Page %s', '_s' ), max( $paged, $page ) );
}
return $title;
}
add_filter( 'wp_title', 'theme_name_wp_title', 10, 2 );
You can simply use simply :
<title><?php wp_title(); ?></title>
For more help go to here
Related
I recently installed a plugin for wordpress/woocommerce that allows you to choose a primary category for a product when it's in multiple categories. It works well to change the breadcrumbs, but my theme (peakshops) also displays the primary category under the corresponding thumbnails on the the shop page.
This is the core function that is built into the theme to display the category (and link to the category) under the thumbnail:
// Add Title with Link.
function thb_template_loop_product_title() {
global $product;
$product_url = apply_filters( 'woocommerce_loop_product_link', get_the_permalink(), $product );
?>
<?php
if ( 'on' === ot_get_option( 'shop_product_listing_category', 'on' ) ) {
$shop_product_listing_category_single = ot_get_option( 'shop_product_listing_category_single', 'on' );
?>
<div class="product-category">
<?php
if ( 'on' === $shop_product_listing_category_single ) {
$product_cats = wc_get_product_category_list( get_the_ID(), '\n', '', '' );
if ( $product_cats ) {
list( $first_part ) = explode( '\n', $product_cats );
echo wp_kses(
$first_part,
array(
'a' => array(
'href' => array(),
'rel' => array(),
),
)
);
}
} else {
echo wc_get_product_category_list( $product->get_id(), ', ' );
}
?>
</div>
<?php } ?>
<h2 class="<?php echo esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ); ?>"><?php the_title(); ?></h2>
<?php
}
add_action( 'woocommerce_shop_loop_item_title', 'thb_template_loop_product_title', 10 );
This core function seems to grab the first category rather than the primary category assigned by the plugin. Is there a way to change this action (or remove it and create a new one) so that it references the primary category assigned. For reference, the primary category plugin stores the value as a post meta field like this:
I'm using a theme which has an ajax filter for the product category pages, and it works really well.
The only thing is that the button wish is displayed, when someone is selecting filters, don't reset them, it directs the visitor back to the shop page. How can I change the logic of the button, that it would just reset the selected filters? So that the users stay on the page where they are? Because right now the button makes no sense.
Thx so far.
HTML
<div class="nm-shop-results-bar has-filters is-category">
<a href="http://localhost/amaoni/" id="nm-shop-filters-reset" data-shop-url="http://localhost/amaoni/">
<i class="nm-font nm-font-close2"></i>Filters active <span>(1)</span></a>
<a href="http://localhost/amaoni/" id="nm-shop-search-taxonomy-reset" data-shop-url="http://localhost/amaoni/"
<i class="nm-font nm-font-close2"></i>Showing <span>“Hundebetten”</span></a>
</div>
PHP
<?php
/**
* NM: Shop - Results bar/button
*/
defined( 'ABSPATH' ) || exit;
global $nm_theme_options;
$results_bar_class = '';
$results_bar_buttons = array();
// Filters
$filters_count = nm_get_active_filters_count();
if ( $filters_count ) {
$results_bar_class = ' has-filters';
$results_bar_buttons['filters'] = array(
'id' => 'nm-shop-filters-reset',
'title' => sprintf( esc_html__( 'Filters active %s(%s)%s', 'nm-framework' ), '<span>', $filters_count, '</span>' )
);
}
// Search
if ( ! empty( $_REQUEST['s'] ) ) { // Is search query set and not empty?
$results_bar_class .= ' is-search';
$results_bar_buttons['search_taxonomy'] = array(
'id' => 'nm-shop-search-taxonomy-reset',
'title' => sprintf( esc_html__( 'Search results for %s“%s”%s', 'nm-framework' ), '<span>', esc_html( $_REQUEST['s'] ), '</span>' )
);
}
// Taxonomy
else if ( is_product_taxonomy() ) {
$results_bar_buttons['search_taxonomy'] = array(
'id' => 'nm-shop-search-taxonomy-reset'
);
$current_term = $GLOBALS['wp_query']->get_queried_object();
if ( is_product_category() ) {
$results_bar_class .= ' is-category';
$results_bar_buttons['search_taxonomy']['title'] = sprintf( esc_html__( 'Showing %s“%s”%s', 'nm-framework' ), '<span>', esc_html( $current_term->name ), '</span>' );
} else {
$results_bar_class .= ' is-tag';
$results_bar_buttons['search_taxonomy']['title'] = sprintf( esc_html__( 'Products tagged %s“%s”%s', 'nm-framework' ), '<span>', esc_html( $current_term->name ), '</span>' );
}
}
if ( ! empty( $results_bar_buttons ) ) :
?>
<div class="nm-shop-results-bar <?php echo esc_attr( $results_bar_class ); ?>">
<?php
$shop_url = esc_url( get_permalink( wc_get_page_id( 'shop' ) ) );
foreach ( $results_bar_buttons as $button ) {
printf( '<i class="nm-font nm-font-close2"></i>%s',
$nm_theme_options['shop_filters_enable_ajax'] ? '#' : $shop_url,
$button['id'],
$shop_url,
$button['title']
);
}
?>
</div>
<?php endif; ?>
I think that's the code part which directs the users to the shop page, but i don't know how to change it, so that it just reset the selected filters.
<div class="nm-shop-results-bar <?php echo esc_attr( $results_bar_class ); ?>">
<?php
$shop_url = esc_url( get_permalink( wc_get_page_id( 'shop' ) ) );
foreach ( $results_bar_buttons as $button ) {
printf( '<i class="nm-font nm-font-close2"></i>%s',
$nm_theme_options['shop_filters_enable_ajax'] ? '#' : $shop_url,
$button['id'],
$shop_url,
$button['title']
);
}
?>
</div>
<?php endif; ?>
Javascript
if (self.filtersEnableAjax) {
/* Bind: Results bar - Filters reset link */
self.$shopWrap.on('click', '#nm-shop-filters-reset', function(e) {
e.preventDefault();
var resetUrl = location.href.replace(location.search, ''); // Get current URL without query-strings
self.shopGetPage(resetUrl);
});
/* Bind: Results bar - Search/taxonomy reset link */
self.$shopWrap.on('click', '#nm-shop-search-taxonomy-reset', function(e) {
e.preventDefault();
var $resetButton = $(this);
if ($resetButton.closest('.nm-shop-results-bar').hasClass('is-search')) {
// Search
var urlSearchParam = self.urlGetParameter('s'), // Check for the "s" parameter in the current page URL
// Search from external page: Get default/main shop URL (current URL may not be the default shop URL)
// Search from shop page: Get current URL without query-strings (current URL is a shop URL)
resetUrl = (urlSearchParam) ? $resetButton.data('shop-url') : location.href.replace(location.search, '');
} else {
// Category or tag
var resetUrl = $resetButton.data('shop-url'); // Get default/main shop URL
}
self.shopGetPage(resetUrl);
});
}
}
I'm trying to get my pagination working with a custom downloads page on my site. I'm using Easy Digital Downloads as my store backend and I'm calling the store items in a custom wp_query. I have the same code working to paginate my archives, but for some reason, it's not working here. I would greatly appreciate any help that can be offered. Here is my code:
From my functions.php file
/* Pagination numbers function
------------------------------------
Allows Google-like page numbers to post pages by calling function */
function custom_numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class="navigation"><ul>' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li>%s</li>' . "\n", get_next_posts_link() );
echo '</ul></div>' . "\n";
}
MY Query
<?php
// Allow Pagination
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }
// Arguments
$type = 'download';
$args=array(
'post_type' => $type,
'posts_per_page' => -1,
'posts_per_page' => 16,
'paged' => $paged
);
// Get results
$my_download_query = new WP_Query($args);
// The Loop
if( $my_download_query->have_posts() ) {
while ($my_download_query->have_posts()) : $my_download_query->the_post(); ?>
<div id="store-item">
<?php
// Check for thumbnail
if ( has_post_thumbnail() ) {
echo '<a href="' . the_permalink() . '" title="' . the_title_attribute() . '" >';
echo the_post_thumbnail('store-thumb');
echo '</a>';
}?>
<?php
$content = get_the_content();
echo string_limit_words($content,20) . '...';
?>
<!-- Get Price -->
<p class="price"><?php echo edd_price_range( $download_id ); ?></p>
<div class="call-to-action-button">
<a type="button" href="<?php the_permalink()?>">Details</a>
</div>
<?php edit_post_link(); ?>
</div> <!-- END #store-item -->
<?php endwhile; ?>
<!-- Call custom numbered pages -->
<?php custom_numeric_posts_nav(); ?>
<div class="navigation"><p><?php posts_nav_link(); ?></p></div>
<?php } ?> <!-- endif -->
?>
That's because inside custom_numeric_posts_nav() you're using the global variable $wp_query, whereas $my_download_query in your custom query.
You could change custom_numeric_posts_nav() to accept the variable $my_download_query as an optional parameter and, if passed, use that:
function custom_numeric_posts_nav( $query = '' ) {
if(!$query)
$query = $GLOBALS['wp_query'];
/** Stop execution if there's only 1 page */
if( $query->max_num_pages <= 1 )
return;
// ... and change the rest of the function accordingly ...
}
And this when you call it:
<!-- Call custom numbered pages -->
<?php custom_numeric_posts_nav( $my_download_query ); ?>
I'm using a wordpress theme that creates custom pages.
However, when SEO Yoast is used to make custom title and meta descriptions, all the custom pages have the same title tags as index.php (the homepage). This is a red flag for google webmaster tools obviously.
add_action('theme_query', 'theme_page_query');
function theme_page_query() {
global $wp_query;
$act = get_query_var( 'act' );
if ($act == 'new-wallpapers') {
query_posts('orderby=post_date&order=DESC&paged='.get_query_var('page'));
} elseif ($act == 'popular-wallpapers') {
query_posts('meta_key=theme_hit_download&orderby=meta_value_num post_date&order=DESC&paged='.get_query_var('page'));
} elseif ($act == 'random-wallpapers') {
query_posts('orderby=rand&paged='.get_query_var('page'));
} elseif ($act == 'recent-downloads') {
query_posts('meta_key=theme_hit_download_time&orderby=meta_value&order=DESC&paged='.get_query_var('page'));
}
}
function theme_page_title($title) {
if (in_array(get_query_var( 'act' ), array(
'new-wallpapers',
'popular-wallpapers',
'random-wallpapers',
'recent-downloads',
))) {
$title = ucwords(str_replace('-', ' ', get_query_var( 'act' )));
}
return $title;
}
add_filter( 'wp_title', 'theme_wp_title', 10, 2 );
function theme_wp_title( $title, $sep ) {
global $paged, $page, $wp_query;
if ( is_feed() ) {
return $title;
}
if (in_array(get_query_var( 'act' ), array(
'new-wallpapers',
'popular-wallpapers',
'random-wallpapers',
'recent-downloads',
))) {
$title = ucwords(str_replace('-', ' ', get_query_var( 'act' ))) . " {$sep} ";
}
// Add the site name.
$title .= get_bloginfo( 'name' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title = "$title $sep $site_description";
}
// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 ) {
$title = "$title $sep " . sprintf( __( 'Page %s', 'theme' ), max( $paged, $page ) );
}
return $title;
}
I have tried searching, but I cannot find a step-by-step guide and I am not good in PHP. Any help would be much appreciated.
You can do this in three steps by
1.Add a new input box to the admin pages for creating and editing new Posts/Pages
2.Save the the value of that input box when that Post/Page is saved
3.Echo out a new title as part of the wp_head() function
here is the detailed explanation..Hope it helps ..Thanks
I have developed a wordpress theme. There are 2 pages HOME and ABOUT US. For home page I use index.php and for about us page I used page.php template. But when I click on home page it shows the title "page not found".
And I create a page named HOME then it is showing page contents which I posted in Home page but I need to show contents of index.php. (for example in index.php I have a slider. and I have created a page named "Home". When I click on home tab it is showing the contents that I posted on home page, NO SLIDER IS SHOWING)
Here is the site admission247.com
my page.php code
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="page_content">
<?php // echo '<br/><br/>'; ?>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
It's difficult to tell without seeing the code.
Here is a snippet of code I use for my header.
<title><?php
global $page, $paged;
wp_title("«", true, "right");
bloginfo("name");
$site_description = get_bloginfo("description", "display");
if($site_description && (is_home() || is_front_page()))
echo " « $site_description";
if($paged >= 2 || $page >= 2)
echo " « " . sprintf(__("Page %s", "h18"), max($paged, $page));
?></title>
If you can, post as much code as you can. It will help others understand your problem more.
YOUR_try this
functions.php
function site_wp_title( $title, $sep ) {
global $paged, $page;
if ( is_feed() )
return $title;
// Add the site name.
$title .= get_bloginfo( 'name' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title = "$title $sep $site_description";
// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 )
$title = "$title $sep " . sprintf( __( 'Page %s', 'YOUR_SITE' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'site_wp_title', 10, 2 );
header.php
<title><?php wp_title( '|', true, 'right' ); ?></title>