Author: Genx

  • How to prevent WooCommerce products from being displayed when searching from the WordPress regular search widget

    How to prevent WooCommerce products from being displayed when searching from the WordPress regular search widget

    If you have WooCommerce installed in WordPress, all posts, pages, and products will be displayed when you search from the regular search widget. Today I will introduce a code that does not display the product and page when searching from the regular search widget. Put the following code in functions.php.

    /** Remove WooCommerce products and WordPress page results from search form widget */
       function mycustom_modify_search_query( $query ) {
         // Make sure this isn't the admin or is the main query
         if( is_admin() || ! $query->is_main_query() ) {
           return;
         }
         // Make sure it is not a WooCommerce product search form
         if( isset($_GET['post_type']) && ($_GET['post_type'] == 'product') ) {
           return;
         }
         if( $query->is_search() ) {
           $in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
           // Type of post to delete (Example: "product" and "page")
           $post_types_to_remove = array( 'product', 'page' );
           foreach( $post_types_to_remove as $post_type_to_remove ) {
             if( is_array( $in_search_post_types ) && in_array( $post_type_to_remove, $in_search_post_types ) ) {
               unset( $in_search_post_types[ $post_type_to_remove ] );
               $query->set( 'post_type', $in_search_post_types );
             }
           }
         }
       }
       add_action( 'pre_get_posts', 'mycustom_modify_search_query' );
  • Code to exclude certain categories from search results in WordPress

    Code to exclude certain categories from search results in WordPress

    When selling paid articles on WordPress, if the search term is included in the paid article, by default the paid article will also be displayed in the search results.

    (more…)
  • How to stop RSS Feed in WordPress

    How to stop RSS Feed in WordPress

    Put the following code in functions.php.

    function wpb_disable_feed() {
    wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
    }
    
    add_action('do_feed', 'wpb_disable_feed', 1);
    add_action('do_feed_rdf', 'wpb_disable_feed', 1);
    add_action('do_feed_rss', 'wpb_disable_feed', 1);
    add_action('do_feed_rss2', 'wpb_disable_feed', 1);
    add_action('do_feed_atom', 'wpb_disable_feed', 1);
    add_action('do_feed_rss2_comments', 'wpb_disable_feed', 1);
    add_action('do_feed_atom_comments', 'wpb_disable_feed', 1);
  • How to stop scaling images in WordPress

    How to stop scaling images in WordPress

    To stop the function that automatically scales images with a resolution of 2560px or higher when uploading images in WordPress, add the following to functions.php.

    //Disable Scaling Of Image
    add_filter( 'big_image_size_threshold', '__return_false' );
  • How to change the WordPress login screen

    How to change the WordPress login screen

    Put the following in functions.php. Replace “Your Logo Here” and “Your URL Here” with your own.

    function custom_login_logo() {
        echo '<style type="text/css">
            .login h1 a {
              background-image: url(https://sitecreation.genxnotes.com/wp-content/uploads/2023/04/avatar.png) ; // Your Logo Here
              background-position: center center;
    		  background-size: contain;
    	      width: 100%;
            }
        </style>';
    }
    add_action('login_head', 'custom_login_logo');
    
    function login_url(){
    return "https://sitecreation.genxnotes.com"; // Your URL Here
    }
    add_filter('login_headerurl', 'login_url');
  • How to create content that never gets old

    How to create content that never gets old

    Creating content that remains relevant and engaging over time requires a strategic approach. Here are several key strategies to help you craft timeless content:

    (more…)
  • When running a blog, avoid writing outdated articles as much as possible, and update them as soon as they become outdated.

    When running a blog, avoid writing outdated articles as much as possible, and update them as soon as they become outdated.

    Absolutely! Keeping your blog relevant and engaging is crucial for maintaining your audience’s interest and improving your search engine rankings. Here are some strategies to avoid outdated articles and effectively update them:

    (more…)
  • The Importance of Re-Editing Past Articles

    The Importance of Re-Editing Past Articles

    Re-editing past articles is a crucial practice for content creators, bloggers, and businesses alike. It not only enhances the quality of your content but also improves its relevance and visibility. Here’s a closer look at why and how to effectively re-edit your articles.

    (more…)
  • The importance of user-friendly navigation when creating a website

    The importance of user-friendly navigation when creating a website

    Creating a website that is user-friendly is essential for ensuring a positive experience for visitors. One of the most critical aspects of this is navigation. Here’s why user-friendly navigation is so important:

    (more…)
  • Attract users with attractive post titles

    Attract users with attractive post titles

    Creating attractive blog titles is crucial for capturing your audience’s attention and encouraging clicks. Here are some strategies and examples to help you craft compelling titles:

    (more…)