Skip to content

Instantly share code, notes, and snippets.

View imelgrat's full-sized avatar

Iván Melgrati imelgrat

View GitHub Profile
@imelgrat
imelgrat / hentry-remove.php
Last active February 9, 2018 14:50
Easy fix to remove 'hentry' CSS class from the post_class() list in WordPress posts
<?php
/**
* @author Ivan Melgrati
* @copyright 2018
*/
/**
* Easy fix to remove 'hentry' from the post_class() list
*
@imelgrat
imelgrat / bulk-post-create.php
Last active May 30, 2021 04:07
Create posts in WordPress from data in a MySQL database. Full article at: http://imelgrat.me/wordpress/bulk-upload-custom-posts-wordpress/
<?php
// Create posts in WordPress from data in a MySQL database. Full article at: http://imelgrat.me/wordpress/bulk-upload-custom-posts-wordpress/
//Load WordPress functions and plug-ins. Put correct path for this file. This example assumes you're using it from a sub-folder of WordPress
require_once ('../wp-load.php');
$database['hostname'] = 'SERVER';
$database['username'] = 'USER';
$database['password'] = 'PASSWORD';
$database['database'] = 'DATABASE';
@imelgrat
imelgrat / products-post-type.php
Last active August 23, 2017 18:06
Declare and configure a new custom post type (Product) in WordPress. Full article at: http://imelgrat.me/wordpress/bulk-upload-custom-posts-wordpress/
<?php
// Only declare the function if it doesn't exist (prevents PHP fatal error)
if (!function_exists('product_post_type'))
{
function product_post_type() // Function to register new custom post type
{
// Labels used inside the WordPress CMS
$labels = array(
'name' => _x('Products', 'Post Type General Name', 'text_domain'),
'singular_name' => _x('Product', 'Post Type Singular Name', 'text_domain'),
@imelgrat
imelgrat / add-column-middle.php
Last active August 23, 2017 18:11
Add a custom column to Wordpress Post management page after title column: Full article at: http://imelgrat.me/wordpress/customize-wordpress-post-management-page/
add_filter('manage_posts_columns', 'add_column_middle'); // Register filter
function add_column_middle($defaults)
{
$new_columns = array(); // Create empty array to store new column order
foreach ($defaults as $key => $value)
{
$new_columns[$key] = $value; // Add columns to new array
if ($key == 'title')
@imelgrat
imelgrat / show-wordcount.php
Last active June 22, 2018 08:05
Display posts word-count column in Wordpress post manage page: Full article at: http://imelgrat.me/wordpress/customize-wordpress-post-management-page/
function post_word_count($post_id) {
$content = get_post_field( 'post_content', $post_id );
$word_count = str_word_count( strip_tags( strip_shortcodes($content) ) );
return $word_count;
}
add_filter('manage_posts_columns', 'wordcount_column');
function wordcount_column($columns) {
$columns['wordcount'] = 'Word count';
return $columns;
@imelgrat
imelgrat / wordcount.php
Last active August 23, 2017 18:11
Calculate the number of words in a Wordpress post. Full article at: http://imelgrat.me/wordpress/customize-wordpress-post-management-page/
function post_word_count($post_id) {
$content = get_post_field( 'post_content', $post_id );
$word_count = str_word_count( strip_tags( strip_shortcodes($content) ) );
return $word_count;
}
@imelgrat
imelgrat / "Rotate-on-Hover" 3D Gallery using CSS3 transforms.markdown
Created September 27, 2015 13:38
"Rotate-on-Hover" 3D Gallery using CSS3 transforms
@imelgrat
imelgrat / Disable PUT and DELETE Apache requests and disable Server signature display
Last active September 27, 2015 13:39
Disable PUT and DELETE Apache requests and disable Server signature display
Disable PUT and DELETE Apache requests and disable Server signature display
@imelgrat
imelgrat / .htaccess
Last active August 23, 2017 19:31
Deny access to WordPress wp-config.php file using .htaccess. Full article at: http://imelgrat.me/security/wordpress-htaccess-file-protect/
# Deny access to wp-config.php file
<files wp-config.php>
order allow,deny
deny from all
</files>
@imelgrat
imelgrat / .htaccess
Last active August 23, 2017 19:42
Deny all access to Wordpress' wp-includes directory using .htaccess. Full article at: http://imelgrat.me/security/wordpress-htaccess-file-protect/
# Block wp-includes folder and files
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>