Skip to content

Instantly share code, notes, and snippets.

/* Automatically set the image Title, Alt-Text, Caption & Description upon upload
--------------------------------------------------------------------------------------*/
add_action( 'add_attachment', 'my_set_image_meta_upon_image_upload' );
function my_set_image_meta_upon_image_upload( $post_ID ) {
// Check if uploaded file is an image, else do nothing
if ( wp_attachment_is_image( $post_ID ) ) {
$my_image_title = get_post( $post_ID )->post_title;
@slavapas
slavapas / FUNCTIONS.PHP with DEFINE VARIALBLES
Created January 14, 2021 18:59
standart functions.php with varialbes PATH
<?php
// define constant
define('PS_THEME_ROOT', get_template_directory_uri());
define('PS_CSS_DIR', PS_THEME_ROOT . '/assets/css');
define('PS_JS_DIR', PS_THEME_ROOT . '/assets/js');
define('PS_IMG_DIR', PS_THEME_ROOT . '/assets/img');
// правильный способ подключить стили и скрипты
add_action('wp_enqueue_scripts', 'theme_name_scripts');
@slavapas
slavapas / front-page.php
Created December 29, 2020 16:49 — forked from codigoconjuan/front-page.php
Bootstrap 4 Slider with WordPress
<div id="main-slider" class="carousel slide mt-4" data-ride="carousel">
<?php $args = array(
'posts_per_page' => 5,
'tag' => 'slider'
);
$slider = new WP_Query($args);
if($slider->have_posts()):
$count = $slider->found_posts;
?>
@slavapas
slavapas / hide-element-untill-page-loaded.js
Created November 4, 2020 21:22
hide HTML element untill page loaded using jQuery
// ------------------------------------
// Hide the element untill page loaded
// ------------------------------------
// HTML
<div id="my-modals" class="hide">
// CSS
.hide {
dislplay:none;
@slavapas
slavapas / functions.php
Last active May 25, 2021 12:04
ACF functions.php and index.php how to call them
<?php
// in functions.php create the CUSTOM POST TYPE
// create CPT = reviews
add_action('init', 'my_first_post_type');
function my_first_post_type()
{
// for thumbnails to be recognised
add_theme_support('post-thumbnails');
// CPT reviews
register_post_type('reviews', [
@slavapas
slavapas / .gitignore
Created October 14, 2020 19:04
.gitignore for GIT in WordPress
/*
!wp-content/
.*
!.gitignore
!readme.md
~*
@slavapas
slavapas / Custom Post Types
Created October 5, 2020 20:17
Define and post Custom Post Type #Wordpress
<?php
// Register Custom Post Type in functions.php
add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
function add_my_post_types_to_query( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'movies' ) );
return $query;
}
@slavapas
slavapas / index.html
Created August 20, 2020 21:12 — forked from d3noob/index.html
leaflet.js map with marker options
<!DOCTYPE html>
<html>
<head>
<title>Marker Leaflet Map</title>
<meta charset="utf-8" />
<link
rel="stylesheet"
href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css"
/>
</head>
@slavapas
slavapas / functions.php
Last active January 6, 2021 13:33
function.php
<?php
function my_styles_scripts_method(){
// load main style.css
wp_enqueue_style('main_style', get_stylesheet_uri());
//load aditional css file
wp_enqueue_style('default_style', get_template_directory_uri().'/assets/css/default.css');
wp_enqueue_style('layout_style', get_template_directory_uri().'/assets/css/layout.css');
wp_enqueue_style('media_queries_style', get_template_directory_uri().'/assets/css/media-queries.css');
// load scripts
@slavapas
slavapas / search icon transform in search box.html
Created March 27, 2019 20:16
search icon transform in search box.html
<div class="searchBox">
<input type="text" class="searchInput" placeholder="Search">
<div class="searchHandle"></div>
</div>
-----------------
*{
box-sizing: border-box;
}