When navigating to the next page of search results in Woocommerce, the title shows as
Search results: “example” – Page 2
I would like to know how I can customise this so the page number is not shown. Ideally, it would be nice to be displayed as
Search results for Example
I have looked in the files and this title seems to be called using
<?php woocommerce_page_title(); ?>
So there's not much there for me to work on.
There are lots of posts on removing the title all together, nothing on how to customise it.
You can use woocommerce_page_title hook to alter the title
according to your need.
Here is a working code:
// define the woocommerce_page_title callback
function filter_woocommerce_page_title($page_title)
{
if (is_search())
{
$page_title = 'Search results for ' . ucfirst(get_search_query());
}
return $page_title;
}
// add the filter
add_filter('woocommerce_page_title', 'filter_woocommerce_page_title', 10, 1);
Code goes in functions.php file of your active child theme (or theme). Or also in any plugin php files.
Hope this helps!
Related
I want to know if it's possible to display specific posts when I click on a link from a specific page to the (ex: gallery page).
Example: Let's say I have 3 posts with 3 different galleries. (post 1=wedding pictures / post 2=food pictures / post 3=dogs pictures) and I also have 3 pages.
When I'm on Page 1 and click on the gallery page link, I want to only show post 1 content (only wedding pictures). When I'm on Page 2 and click on the gallery page link, I want to display only the post 2 content.
If It's possible what would be the most simple solution?
Thank you!
To show specific posts based on type, category, tag or any other property, your best bet is to use a shortcode, which gives you lots of versatility in how to render the items (in a post, page, widget, template file, etc).
The shortcode could be generated by a plugin such as Bill Erickson's Display Posts, Content Views or 10's of other plugins.
Or do it manually by building your own "show some posts" shortcode and get a much better understanding of WP. You'll have to build your own html output, filters and paging, but you will end up with less plugins gumming up your installation. There's lots of tutorials for this, search for "Wordpress display posts shortcode functions.php".
E.g. Placing the following in your theme's (ideally, a child theme) functions.php file, here is a way to show a specific number of posts from a specific content type:
Place in functions.php:
function show_some_posts($atts) {
$a = shortcode_atts([
'post_type' => 'post',
'posts_per_page' => 3
], $atts);
$the_query = new WP_Query( $a );
if ( $the_query->have_posts() ) {
$string .= '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$string .= '<li>' . get_the_title() . '</li>';
}
wp_reset_postdata();
$string .= '</ul>';
} else {
$string .= 'no posts found';
}
return $string;
}
function shortcodes_init()
{
add_shortcode('get-posts','get_some_posts');
}
add_action('init', 'shortcodes_init');
And to render the actual list, place this shortcode in your page or post:
[get-posts posts_per_page="3"]
You can first assign each photo (or post containing a photo) a category e.g. Wedding, food etc.
Once that is done, create a custom menu and add the categories to it. Place this menu on an area of your page and give it a try. It should only show the required images/posts.
For more info, you can have a look at the link below:
https://en.support.wordpress.com/category-pages/
Note: You may need a plugin to allow you to place categories on images. Have a look at an example at the link below:
https://wordpress.org/plugins/categories-images/
I have made a simple shortcode for my wordpress theme. I'm trying to align it on right-side above the corner of my page. Is it possible to insert shortcode function.php?
I want to place my Short-code in the top-bar (right side above the corner) so that it will work for each pages. Means if i click on any menu then the shortcode should have to work on that menu also.
Actually i'm new in web development. Please suggest me what shall i have to do so it will align where i want and should have work for each module.
You can use wordpress function for that. Please open the file on which you have to place shortcode. Like if you want to place it on header open header.php and add
<?php echo do_shortcode('[your_shortcode]'); ?>
where you want your shortcode content to appear
The best way is to find the top bar menu hook of your theme and then add this code (adapted for your needs) in your function.php child theme :
function my_shotcode_inside_top_bar ( $items, $args ) {
if (is_page() && $args->theme_location == 'secondary') {
$items .= '<li class="my-class">' . do_shortcode( "[my_shortcode]" ) . '</li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_shotcode_inside_top_bar', 10, 2 );
is_page displays the shortcode in pages only but you can choose another condition or no condition at all.
secondary is the hook and it depends on your theme. You can normally find it in your theme header.php file.
A menu location selector should be added - that way some themes support multiple menus, and some are called "top" or custom added.
The shortcode could then contain a call to whatever a menu position is:
EG: [myshortcode menu="secondary"]
Didn't have enough points to add this as a comment.
I'm using Genesis framework and I have this page (http://staging.seedcreativeacademy.co.uk/short-courses/) showing the categories of my custom post type short_courses. I have changed the category name to course_type, by creating a new custom taxonomy.
This is how I want it to work so far (styling needs sorting out admittedly!) Im also using CPT UI plugin.
Now, when I click through to a category, is displays each 'Course in a nice masonry block as you will see here: http://staging.seedcreativeacademy.co.uk/course_type/digital-marketing/
However, I dont want this pages to look like this and I've tried adding custom template for the following:
Archive-short_courses.php & taxonomy-short_courses.php
Archive-course_type.php & taxonomy-course_type.php
But it doesnt seem to alter the layout at all...
Once I pass this hurdle I will want to alter the single.php page for these short courses, but I thought I would start with this first.
Im not sure if genesis blocks this and sets a site wide default? I know if sets a site wide default for the archive settings but I cant find anything about a template, plus i dont know if I shoujld be searching for tutorials on archive.php pages, category.php pager or taxonomy.php pages...
Can someone help me clarify things please?
course_type is a term name, not taxonomy name.
So, these are correct for your case:
category-course_type.php (category-{slug}.php is correct format. So check if course_type is correct slug of that category)
single-short_courses.php
Just in case, try reload permalinks via Settings->permalinks->save after making these changes.
Looks like your theme or some plugin is adding masnory class to body tag, which then is styled by your child theme. You need to filter that class out of your body tag and then might styling goes to non-masonary styling.
Add following code to your taxonomy-course_type.php file, and also make sure you have genesis(); call as the last thing in the template.
add_filter('body_class', 'remove_body_class', 20, 2);
function remove_body_class($wp_classes)
{
foreach($wp_classes as $key => $value)
{
if ($value == 'masonry') unset($wp_classes[$key]);
}
return $wp_classes;
}
Above could should be in custom taxonomy template, which also have genesis(); as last line.
I have a photo gallery page that is using a single page in Wordpress.
The gallery display is dynamic, and relies on a URL parameter. The parameter itself is an integer of the relating wordpress page ID. (as that's the page it's about).
Here is an example of a gallery URL:
http://www.bellavou.co.uk/gallery/?pid=238
For SEO purposes, I'm trying to get away from every possible Gallery URL combination to have the page title 'Gallery', as is set in the Wordpress page settings.
I've been trying this, which has been mentioned a few times:
function assignPageTitle(){
return "Title goes here";
}
add_filter('wp_title', 'assignPageTitle');
But as I'm also using Yoast SEO plugin, I think this is over-writing it (even though I uncheck 'Force title rewrite', and keep the page title field blank). Not sure why the above function doesn't seem to work.
Within the gallery page, I'm able to show the h1 title properly, passing PHP Variables into the code, but I want to do the same to the page title, but in a way that can be done directly on the page template.
Why is it that whenever I post a question, I seem to find the answer very soon afterwards?
I read a post saying that it helps to put a wp_title function before the wp_header call, which is what I tried, and that seems to work fine.
I can edit the page title just for an individual page using the PHP page template, and using this:
$procedure = isset($_GET['pid']) ? $_GET['pid'] : '';
add_filter( 'wp_title', 'wp_title_gallery', 100 );
function wp_title_gallery($title) {
global $procedure;
if(!$procedure) {
$title = the_title();
} else {
$title = the_title(get_the_title($procedure).' ');
}
return $title;
}
get_header();
$procedure gets the URL parameter, and then the function takes that ID, and gets the associated page from it, and then prints the title of the page, into the page title hook. Lastly, the WP header is called.
(Just incase anyone comes here looking for a solution)
Does anyone know of a way to change the title of a page that is created dynamically in Wordpress? The pages in question are created dynamically via a plugin, and do not appear in the list of pages or Wordpress SEO in the admin section.
Here is an example of a page I would like to change the title of: http://www.forestlakechevrolet.com/inventory/New/
The inventory tool is maintaining the inventory of two dealerships, but only one is featured on this site. So it uses an SEO title based on the makes available at both dealerships.
Essentially, I am wondering if there is a function that I could add that would say "If URL is ... then force page title to be ***."
Does anyone know how to do this?
Thank you,
Jared Wilcox
Just use the wp_title filter
Add something like this to your theme's functions.php file:
<?php
function assignPageTitle( $title ){
global $post;
if ($post->post_name === "test") {
$title = "Title goes here";
}
return $title;
}
add_filter('wp_title', 'assignPageTitle');
?>
You may also need to change your theme's header file if the wp_title call is adding the Site Name.
BTW, WordPress questions are better asked on https://wordpress.stackexchange.com/