• Skip to main content
  • Skip to primary sidebar

WordPress, Genesis Framework and Storefront customization tutorials

  • Archive
    • Free
    • Premium
  • Blog
  • About
  • Contact
  • Newsletter
  • Membership
  • Login
Home » WordPress

WordPress

Fixing Site Health’s Security Headers Error WordPress

Add this snippet to .htaccess

# Really Simple SSL
 Header always set Strict-Transport-Security: "max-age=31536000" env=HTTPS 
 Header always set Content-Security-Policy "upgrade-insecure-requests"
 Header always set X-Content-Type-Options "nosniff"
 Header always set X-XSS-Protection "1; mode=block"
 Header always set Expect-CT "max-age=7776000, enforce"
 Header always set Referrer-Policy: "no-referrer-when-downgrade"
# End Really Simple SSL
  • HSTS – When this header is set on your domain, a browser will do all requests to your site over HTTPS from then on.
  • Upgrade-Insecure-Requests – This header is an additional method to force requests to your own domain over https://.
  • X-Content-Type-Options – This header will force the browser not to “guess” what kind of data is passed. If the extension is “.doc”, the browser should get a .doc file, not something else (a .exe).
  • X-XSS-Protection – Will stop pages from loading if a reflected cross-site scripting (XSS) attack is detected.
  • Expect-CT, Certificate Transparency – A Certificate Authority (the issuer of the SSL certificate) needs to log the certificates that are issued in a separate log, the CT framework., preventing fraud.
  • No Referrer When Downgrade header – Only sets a referrer when going from the same protocol and not when downgrading (HTTPS -> HTTP).

Filed Under: Free Tagged With: WordPress

Add Featured Image with a Function

Filed Under: Free Tagged With: WordPress

How to add Pagination to the Archive of Custom Post Type in any WordPress Theme

Pagination function

Create a file named pagination.php in yout child theme and include it in your functions.php

<?php 
// numbered pagination
function pagination($pages = '', $range = 4)
{  
     $showitems = ($range * 2)+1;  
  
     global $paged;
     if(empty($paged)) $paged = 1;
  
     if($pages == '')
     {
         global $the_query;
         $pages = $the_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   
  
     if(1 != $pages)
     {
         echo "<div class=\"archive-pagination pagination\">";
         echo "<ul>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'> 
         <span class='double-chevron-wrapper'>
                <i class='fas fa-chevron-left first'></i>
                <i class='fas fa-chevron-left second'></i>
         </span>
            </a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'> <i class='fas fa-chevron-left prev'></i></a>";
  
         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<li><span class=\"current\">".$i."</span></li>":"<li><a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a></li>";
             }
         }
  
         if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\"><i class='fas fa-chevron-right next'></i></a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>
            <span class='double-chevron-wrapper'>
                <i class='fas fa-chevron-right first'></i>
                <i class='fas fa-chevron-right second'></i>
            </span>
            </a>";
         echo "</ul>\n";
         echo "</div>\n";
          
         echo "<div class='all_pages'><small>Current page: ".$paged." All pages ".$pages."</small></div>";
     }
}

?>

Create the WordPress Loop

Add the name of your terms

Set the posts_per_page value in the args

<?php
wp_reset_postdata();

$terms_name = 'YOUR_TERMS_NAME';

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  
$args = array(
    'post_type' => 'YOUR_POST_TYPE',
    'posts_per_page' => 2,
    'paged' => $paged,
    'tax_query' => array(
               array(
                   'taxonomy' => 'YOUR_TAXONOMY',
                   'field'    => 'slug',
                   'terms'    => $terms_name
               ),
           ),
);
  
$the_query = new WP_Query( $args ); ?>

    <!--YOUT CUSTOM CONTENT-->
    
    <h2><?php the_title(); ?></h2>

<?php echo pagination($the_query->max_num_pages); ?>

Add some line of CSS

.archive-pagination.pagination li {
	margin-left: 0 !important;
	margin-right: 10px !important;
}
.current {
	padding: 0.9rem 1.2rem;
	background: #124e84;
    color: white;
}

Filed Under: Free Tagged With: WordPress

Set user capabilities to edit only specific pages in WordPress

1) Install the PublishPress Capabilities plugin

PublishPress Capabilities

2) Create a new user with the role editor

create a new user

3) Uncheck the checkboxes

4) Assign the specific post to the guest user

5) Log in into the guest account with the editor role

As You can see there’s no other pages to edit except this one

 

Filed Under: Free Tagged With: WordPress

User specific CSS for WordPress admin

Add this snippet to functions.php

function add_css_to_guest_user() {
    $guest_user = wp_get_current_user();

    if($guest_user && isset($guest_user->user_login) && 'guest' == $guest_user->user_login) {
        wp_enqueue_style( 'guest_admin_css', get_stylesheet_directory_uri() . '/css/wpadmin-guest.css' );
    }
}
add_action('admin_print_styles', 'add_css_to_guest_user' );

2) CSS

If You want to hide the CF7 menu item on guest user’s WordPress admin use this CSS

#toplevel_page_wpcf7 {
	display: none;
}

Filed Under: Free Tagged With: WordPress

How to add custom menu item to the WordPress nav menu

The content between the li tags could be anything You want!

For example shortcode for language switcher, social icons or custom text.

// =========================================================================
// ADD CUSTOM MENU ITEM TO THE WORDPRESS NAV MENU
// =========================================================================
function add_custom_menu_item ($items, $args) {
    $items .= '<li id="menu-item-5000" class="menu-item menu-item-type-post_type menu-item-object-page last">';
        $items .= 'Last Menu Item';
    $items .= '</li>';
    return $items;
}
add_filter( 'wp_nav_menu_items', 'add_custom_menu_item', 10, 2 );

Filed Under: Free Tagged With: WordPress

How to create custom breadcrumbs in WordPress

Filed Under: Free Tagged With: WordPress

How to create custom Hooks in WordPress

1) Define the custom hook in functions.php

function latest_products_hook() {
	do_action('latest_products_hook');
}

2) Place anywhere you want in your template files

<?php latest_products_hook(); ?>

3) Create the function

add_action( 'latest_products_hook', 'storefront_recent_products', 30);

Filed Under: Free Tagged With: WordPress

WordPress Loop

Display posts on specific pages with WordPress loop

Loop WordPress post titles:

Loop WordPress post titles

You can use these WordPress core functions inside the loop:

the_title();
the_excerpt();
the_content();
the_permalink();
the_post_thumbnail();

Place these PHP functions in your HTML structure and add some line of CSS

Filed Under: Free Tagged With: WordPress

Primary Sidebar

Gabor Flamich

Hi! I'm Gabor.
I write tutorials on WordPress and WooCommerce.

MacBook

12 Essential Snippets for Genesis Developers

Subscribe to my Newsletter to view my basic collection of Genesis snippets that I use for my projects!

Sign Up for Free
  • Facebook
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube
UpdraftPlus Premium

Tags

ACF Ajax Analytics API Bootstrap Breadcrumb category CPT CSS fetch Genesis Google Maps Gutenberg HTML Isotope JavaScript jQuery loop Map Menu Parallax PHP SASS SEO SQL Storefront SVG tab tag manager tags Taxonomy Tool upsell Webpack Wholesale WooCommerce WordPress WPML

Disclosure: Some of the links in this site are affiliate links. I will be paid a commission if you use this link to make a purchase.

  • Privacy Policy / Terms of Service
© 2023 WP Flames - All Right Reserved