Is there plugin for WP to show latest news with specific word in title or somewhere? - wordpress

I need help with WordPress. For example, I have 100 posts in my blog, and only one post has a word: "HOT". I'd like to show this post on the right side (like widget). Can you advise me something?

There are plugins like "Recent Posts Widget Extended" that can filtered by tag or filter the post query on functions.php like :
add_filter( 'rpwe_default_query_arguments', 'your_custom_function' );
function your_custom_function( $args ) {
$args['s'] = 'HOT';
return $args;
}

Related

Show content before main content based on color attribute

I found a code snippet to display the content before the main content and it worked.
Currently the content is displayed on all pages. (except shop page)
The code :
add_action( 'woocommerce_before_main_content', 'BannerShop', 35 );
function BannerShop(){
if(!is_shop()){
echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
}
}
What I want to ask is, how to display content only for color attribute products in the form of links.
Example :
The display (content) will ONLY SHOW when the url is like this :
mysite.com/color/red/
Sorry if the explanation is not good because I don't really understand this.
Any help is greatly appreciated.
thank you
I understand your question is about displaying that extra content, if the current query is for a product archive page only showing products of a certain attribute 'color'.
Each WooCommerce attribute is an independent taxonomy.
WordPress's is_tax('parameter') function checks, if the query is for an existing custom taxonomy archive page (other than category & tag) & if the query is for that specific taxonomy 'parameter', in your case 'color'.
So, this code snippet in your functions.php or equivalent plugin should work:
add_action( 'woocommerce_before_main_content', 'BannerShop', 35 );
function BannerShop(){
(is_tax('color')) {
echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
}
}
Though, to make the above template WooCommerce override work, declare WooCommerce support for your theme by adding the following lines to your functions.php or plugin equivalent:
function theme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'theme_add_woocommerce_support' );

Ordering By Menu Order in the Wordpress REST API?

I am trying to display posts using the REST API and I want to display them in menu order based on how they are positioned in the admin menu.
I installed a plugin that allowed me to move posts to any position in the admin. I know querying the posts the normal way with wordpress there is a orderby: menu_order option, which would do what I am looking for, but I can't figure it out with the REST API.
My REST API looks like this:
https://example.com/wp-json/wp/v2/qd_leadership?_embed&per_page=100&orderby=menu_order
So I've tried that and that does not work. It says menu_order isn't an option. I also saw a post here:
Query WordPress (REST) posts by the order they appear on the admin
That had a similar question. The only answer on that post is to not have any orderby parameter and that should display them in the menu order, but that did not work for me. So I am stumped on how to order the posts from the REST API in menu order?
Its bug of wp core in rest api so you could use below hack for the solution.Please add below code in your active theme's function.php
add_filter( 'rest_post_collection_params', 'my_prefix_add_rest_orderby_params', 10, 1 );
function my_prefix_add_rest_orderby_params( $params ) {
$params['orderby']['enum'][] = 'menu_order';
return $params;
}
Tested and works.
Thanks to raju_eww for the hint in the right direction. But in case of a custom post type collection the filter hook name has to be like this:
add_filter( 'rest_custom-post-type_collection_params', 'my_prefix_add_rest_orderby_params', 10, 1 );
function my_prefix_add_rest_orderby_params( $params ) {
$params['orderby']['enum'][] = 'menu_order';
return $params;
}
found here:
https://www.timrosswebdevelopment.com/wordpress-rest-api-post-order/
Following code do sort by menu_order when orderby is not in query string (for woocommerce):
add_filter('woocommerce_get_catalog_ordering_args', 'am_woocommerce_catalog_orderby');
function am_woocommerce_catalog_orderby( $args ) {
if(!$_GET['orderby']) {
$args['orderby'] = 'menu_order';
$args['order'] = 'asc';
}
return $args;
}
source

How to remove wordpress date archive pages?

I have developed my own wordpress theme, and learning all kinds of programming stuff, but my priority is the content, not the programming knownledge. I need to know how to remove archive date listing from wordpress?
Question 1: The google search results displayed like this: virmodrosti.com/2017/05/
I don't want any kind of date archive option, how do you disable that?
I also don't use any kind of plugin, and always like to do it on my own.
Question 2: I don't know why older entries doesn't work anymore
virmodrosti.com/zdravje/ this page works fine
virmodrosti.com/zdravje/page/2/ it redirects to 404 error page
I only choose option in wordpress to hide that annoying /category/ with dash . inside editor at permanlinks, Category base. Maybe somehow these stuff is kinda fighting with each other and doesn't work properly.
Thank you.
This is code from Digital Nomad theme I maintain:
function digitalnomad_remove_date_archives() {
//if we are on date archive page
if ( is_date() ) {
// theme sets alternatine archive page with table like list of all posts
$archive_page = get_option( 'digitalnomad_archive_page' );
if ( $archive_page ) {
// redirs to alternatine archive page if configured (good for SEO)
wp_redirect( esc_url( get_page_link( $archive_page ) ) );
die();
} else {
// otherwise error 404 is displayed
global $wp_query;
$wp_query->set_404();
}
}
}
add_action( 'template_redirect', 'digitalnomad_remove_date_archives' );
Use the smart Archive Page Remover wordpress plugin
or visit your theme's functions.php file
then insert this code
/* Register template redirect action callback */
add_action('template_redirect','makes_remove_wp_archives');
/* Remove archive*/
function makes_remove_wp_archives(){
// if we are on category or tag or date or author archive
if(is_category()|| is_tag()||is_author()){
global $wp_query;
$wp_query->set_404();
}
}

Woocommerce: How to remove "Archive" in title?

I'm trying to remove the word "Archive" from the page title.
How to remove it? By adding a filter?
Example:
My collections Archive | My sitename
Best to use Wordpress SEO by Yoast.
Within Titles & Metas go to the Taxonomies tab and update the Title template for Product Categories to remove the word Archive. Mine ended up looking like this:
%%term_title%% %%page%% %%sep%% %%sitename%%
you can rewrite the filter in functions.php so it fails, causing WooCommerce not the render it.
function override_page_title() {
return false;
}
add_filter('woocommerce_show_page_title', 'override_page_title');
If you are using the Yoast SEO (VersiĆ³n 8.1.2), the options were move to:
Yoast SEO -> Search Appearance -> Taxonomies.
In there look up by Product categories (product_cat) and open it.
Then remove the Archives string from the head.
I know this is an old post but I tried the answers here and it didn't work.
I found the solution basing it off renegadesk's answer, but in addition of going to the Taxonomies Tab I also had to change it in the Post Types tab. See below:
Get Wordpress SEO by Yoast if you don't already have it, then click SEO > Titles & Metas > Post Types. Scroll down and look for the heading "Custom Post Type Archives". On the "Products", you can edit the content of this title. Mine now looks like this:
%%pt_plural%% %%page%% %%sep%% %%sitename%%
In woocommerce there seem to be 3 instances of Archives (case sensitive) one in
\wp-content\plugins\woocommerce\woocommerce-hooks.php around line 50
and 2 in \wp-content\plugins\woocommerce\woocommerce-template.php
around lines 240 ish
Perhaps one of those is what you're looking for and you may be able to modify code.
in addition to Ted C:
For this purpose Wordpress has already predifined functions starting with __return_.
In this case the function you are looking for is __return_false.
add_filter('woocommerce_show_page_title', '__return_false',10,0); will also work.
The last two params are the order of the function and the number of params passed to it.
It is always a good pratice to set them up but this is only necessary if you want to modify the default order (10) and the number of params passed (1).
You have this filter for all cases : "get_the_archive_title".
But then there are different cases.
For exemple for simple category you can do :
function prefix_category_title( $title ) {
if(is_category()){
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'prefix_category_title' );
For custom post type you should do :
function prefix_category_title( $title ) {
if(is_archive('slug-of-your-custom-post-type')){
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'prefix_category_title' );
So finally you have many condition like :
is_category
is_archive
is_tag
is_author
is_year
is_tax
https://developer.wordpress.org/reference/functions/get_the_archive_title/
Vincent.
wp-content/plugins/woocommerce/templates/archive-product.php
Edit this file archive-product.php and remove the below 3 lines.
<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
<?php endif; ?>
This will remove page title on shop page and all other pages.

is there a way (plugin) to insert html/css/images ect automatically into every wordpress post?

is there a way (plugin) to insert html/css/images ect.. automatically into every wordpress post? most of my posts are going to be very similar so is there a plugin that will automatically insert the pre written html/css/ ect in every post as opposed to me entering it manually every time.
Thank you in advance ;-)
You can write your own simple function for this, see my example below:
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
global $post_type;
if( $post_type == 'post') { /* Or your custom post type, pages etc. */
$content = 'Your custom HTML/CSS content here';
}
return $content;
}
Place this in functions.php and it will be the default content of every new post/page/custom post type you create.
For a list of available post types, please refer to the Codex
You could use a plugin such as Ad injection, it will allow you to do what you need without having to alter / amend / ad any code to the templates or files

Resources