Skip to content

Instantly share code, notes, and snippets.

@AlkarE
AlkarE / dinamic_sidebar
Created June 3, 2015 08:01
dinamic sidebar
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("sidebar name") ) :endif; ?>
@AlkarE
AlkarE / custom_logo.php
Created June 7, 2015 09:15
custom_logo_in_customizer
// custom-logo => goes to function.php
function themeslug_theme_customizer( $wp_customize ) {
$wp_customize->add_section( 'themeslug_logo_section' , array(
'title' => __( 'Branding Logo', 'themeslug' ),
'priority' => 30,
'description' => 'Upload a logo to replace the default site name and description in the header',
) );
$wp_customize->add_setting( 'themeslug_logo' );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'themeslug_logo', array(
'label' => __( 'Logo', 'themeslug' ),
@AlkarE
AlkarE / custom_post.php
Last active August 29, 2015 14:25
custom_post_plugin
<?php
/*Plugin Name: Create Picture post type and Album category
Description: This plugin registers the 'Picture' post type.
Version: 1.0
License: GPLv2
*/
function picture_post_type() {
$labels = array(
'name' => 'Picture',
@AlkarE
AlkarE / ptoduct_cat_taxonomy.php
Created July 20, 2015 08:07
product_category_taxonomy
<?php
/*Plugin Name: Create product Category Taxonomy
Description: This plugin registers the 'product category' taxonomy and applies it to the 'product' post type.
Version: 1.0
License: GPLv2
*/
function product_register_taxonomy() {
// set up labels
$labels = array(
@AlkarE
AlkarE / retina_images
Created January 16, 2016 19:53
retina-images
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min--moz-device-pixel-ratio: 2),
only screen and (-moz-min-device-pixel-ratio: 2),
only screen and (-o-min-device-pixel-ratio: 2/1),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 192dpi),
only screen and (min-resolution: 2dppx) {
/* стили для дисплеев Retina */
}
@AlkarE
AlkarE / wp_server_test
Created January 22, 2016 20:00
wp_server_info
<?php
echo '<div style="text-align: center">WordPress: '
. round(memory_get_usage()/1024/1024, 2) . 'MB '
.' | MySQL:' . get_num_queries() . ' | ';
timer_stop(1);
echo 'sec</div>';
?>
@AlkarE
AlkarE / gist:2ba020802b50471e62b71eb80f5e1fd4
Created August 3, 2016 13:39
wordpress disable embed
<?php
function disable_embeds_init() {
// Remove the REST API endpoint.
remove_action('rest_api_init', 'wp_oembed_register_route');
// Turn off oEmbed auto discovery.
// Don't filter oEmbed results.
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
@AlkarE
AlkarE / disable_cpt_archive.php
Created January 23, 2017 13:13
Disable cpt archive
function disable_cpt_archive_template(){
if ( is_post_type_archive('cpt') ) {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 ); exit();
}
}
add_filter( 'archive_template', 'disable_cpt_archive_template', -1 );
-- Change Siteurl & Homeurl
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com') WHERE option_name = 'home' OR option_name = 'siteurl'
-- Change GUID
UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com')
-- Change URL in Content
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com')
-- Change Image Path Only
@AlkarE
AlkarE / wp_queries.md
Last active May 4, 2017 14:40
Sql queries for migrating WP to https

Update any embedded attachments/images that use http. This one updates the src attributes that use double quotes:

UPDATE wp_posts SET post_content = REPLACE(post_content, 'src="http://www.yoursite.com', 'src="https://www.yoursite.com') WHERE post_content LIKE '%src="http://www.yoursite.com%';

This one takes care of any src attributes that use single quotes:

UPDATE wp_posts SET post_content = REPLACE(post_content, 'src='http://www.yoursite.com', 'src='https://www.yoursite.com') WHERE post_content LIKE '%src='http://www.yoursite.com%';