How about working with a team that puts the worries of the virtual environment aside and makes this burden more attractive to you with its wide range of services?
Contact Now: +90 850 305 25 95
E-mail:info@margarit.com.tr
Address: İvoksan, Neva Home Offices
1455 Street, 22/41 Yenimahalle / Ankara

Common WordPress problems and quick fixes

margarit-web-reklam-bilisim-2020

While there are many nice features of the WordPress CMS system, many plugin and theme features may conflict with each other due to its open source code. In addition, although it is a system preferred by millions, the WordPress ready content management system can be weak in special areas and may need manual intervention. This is the real reason why WordPress, which is distributed with open source code, is already one of the most preferred systems worldwide, so that you can produce custom solutions for your own needs.

However, there are some problems that you cannot get rid of without intervention, we will share a few of them with you and try to express the solutions.

Fix WordPress Cannot redeclare get_avatar_url() error

We are adding the archive solution for the Cannot redeclare get_avatar_url() error to use with our WordPress-loving friends to keep it registered based on the articles we researched and the method we used.

You change the codes in the functions.php file to make arrangements for your theme.

Legacy code:

function get_avatar_url( $get_avatar ) { preg_match("/src='(.*?)'/i", $get_avatar, $matches); return $matches[1]; }

New code:

if(!function_exists('get_avatar_url')){ function get_avatar_url( $get_avatar ) { preg_match("/src='(.*?)'/i", $get_avatar); 1TP3 return $matches[1]; } }

Adding views to WordPress post content without using a plugin

You can easily play with WordPress topic views with SQL commands.

While there are thousands of alternative methods to add fake views to your posts, you can add as many numbers as you want with a code added to the functions.php file inside your theme and make up for your deficiencies manually at this point.

In functions.php:

function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
return $count.' Views';
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
// Remove issues with prefetching adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

Then single.php and index.php We paste it wherever we want.

<?php
echo getPostViews(get_the_ID());
?>

W3 Total Cache If a similar caching plugin is available, we may need additional code:

I am updating.
In Functions.php:

function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
return $count.' Views';
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}

Into pages such as single and index: 

before:

<?php
echo getPostViews(get_the_ID());
?>

Then:

<?php
setPostViews(get_the_ID());
?>

Adding WordPress Woocommerce Front Page Dropdown Droplist

I know the title is too much english. However, we are already writing to add the system we have solved as a note after spending hours in order not to forget it for archival purposes.

<div class="col-md-3 webfilter" id="profilter">
     <div class="prolist col-md-10 errormsg" >
         </div>
 <div class="prolist col-md-10"  >
     <input type="hidden" id="ajaxpath" value="<?php echo get_bloginfo(&#39;template_directory&#39;).&#39;/getproducts.php&#39;; ?>" />
     <select name="brand" class="homedrop" id="brand">
         <option value="">Manufacturer</option>
         <?php
            $args=array(
                   &#39;hide_empty&#39; => 0,
                   &#39;orderby&#39; => &#39;name&#39;,
                   &#39;order&#39; => &#39;ASC&#39;,
                   &#39;hierarchical&#39; => 0,
                   &#39;style&#39; => &#39;none&#39;,
                   &#39;taxonomy&#39; => &#39;product_cat&#39;,
                   &#39;depth&#39; => 0,
                   &#39;parent&#39; => 0
                );
                 $res = get_categories($args);
                foreach($res as $result) {
          echo &#39;<option value="&#39;.$result->term_id.&#39;">&#39;.$result->name.&#39;</option>&#39; ;
                }
          ?>
    </select>
</div>
 <div class="prolist col-md-10">
     <select name="model" class="homedrop" id="model">
        <option>Model</option>
     </select>
 </div>
 <div class="prolist col-md-10">
     <select name="motor" class="homedrop" id="motor">
         <option>Engine</option>
     </select>
 </div>

<div style="color:#FFF !important;" id="findproduct" class="cs-btn-align text-center"><a href="#" style="color:#FFF !important;" class="dropbutton cs-btn cs-btn-outlined avc cs-btn-rounded cs-btn-outlined-accent cs-btn-sm">FIND MY VEHICLE</a></div>

</div>

this code has presented us the image that we will use as a widget on the home page and the optional menu.

Now, with the $category function, let's create a function file to name and retrieve the levels to list all the content on our site.

<?php
require_once( dirname(__FILE__) . &#39;/../../../wp-load.php&#39; );


if($_POST[&#39;action&#39;] == &#39;brand&#39;) {
    $brandid = $_POST[&#39;brand&#39;];
$args=array(
                   &#39;hide_empty&#39; => 0,
                   &#39;orderby&#39; => &#39;name&#39;,
                   &#39;order&#39; => &#39;ASC&#39;,
                   &#39;hierarchical&#39; => 0,
                   &#39;style&#39; => &#39;none&#39;,
                   &#39;taxonomy&#39; => &#39;product_cat&#39;,
                   &#39;depth&#39; => 0,
                   &#39;parent&#39; => $brandid
                );
                $childs = get_categories($args);
$result = array();
$i = 0;
foreach($childs as $child) {
    $result[$i][&#39;id&#39;] = $child->term_id;
    $result[$i][&#39;name&#39;] = $child->name;
    $i++;
}
echo json_encode($result);
die();
}
if($_POST[&#39;action&#39;] == &#39;model&#39;) {
    $brandid = $_POST[&#39;brand&#39;];
$args=array(
                   &#39;hide_empty&#39; => 0,
                   &#39;orderby&#39; => &#39;name&#39;,
                   &#39;order&#39; => &#39;ASC&#39;,
                   &#39;hierarchical&#39; => 0,
                   &#39;style&#39; => &#39;none&#39;,
                   &#39;taxonomy&#39; => &#39;product_cat&#39;,
                   &#39;depth&#39; => 0,
                   &#39;parent&#39; => $brandid
                );
                $childs = get_categories($args);
$result = array();
$i = 0;
$baseurl = get_bloginfo(&#39;url&#39;);
foreach($childs as $child) {
    $result[$i][&#39;id&#39;] = $baseurl.&#39;/product-category/&#39;.$child->slug;
    $result[$i][&#39;name&#39;] = $child->name;
    $i++;
}
echo json_encode($result);    
die();    
}
if($_POST[&#39;action&#39;] == &#39;search&#39;){
    $args = array(
    &#39;post_type&#39; => &#39;product&#39;,
    &#39;posts_per_page&#39; => -1
    );
    $wp_query = new Wp_Query($args);
    $posts = $wp_query->posts;    
    $result = array();
    $i = 0;
    
    foreach($posts as $post) {
    $result[$i][&#39;label&#39;] = $post->post_title;
    $result[$i][&#39;value&#39;] = get_the_permalink($post->ID);
    $thumbid = get_post_thumbnail_id($post->ID);
    $result[$i][&#39;img&#39;] = wp_get_attachment_image( $thumbid, &#39;thumbnail&#39; );
    if($result[$i][&#39;img&#39;] == &#39;&#39;) {
        $result[$i][&#39;img&#39;] = &#39;<img width="80" height="80" src="https://dummyimage.com/80x80/8f8f80/fff.png&text=No+image" class="attachment-thumbnail" alt="product-img" />&#39;;
    }
    
    $i++;    
    }
    //print_r($result);    exit;
    echo json_encode($result);    
    die();
}


?>

We have defined the structure, but I need to add a file of the brand application that I have converted within itself for taxonomy consistency.

Therefore, I create the following file in the same way as in the getproducts.php file and open it to the theme main directory.

<?php
/**
 *
 * Template for Brand taxonomy
 * @since 1.0.0
 * @version 1.0.1
 *
 */



if ( ! defined( &#39;ABSPATH&#39; ) ) {
    exit; // Exit if accessed directly
}
$term     = get_queried_object();
$parent_id         = empty( $term->term_id ) ? 0 : $term->term_id;
        $product_categories = get_categories( apply_filters( &#39;woocommerce_product_subcategories_args&#39;, array(
            &#39;parent&#39;       => $parent_id,
            &#39;menu_order&#39;   => &#39;ASC&#39;,
            &#39;hide_empty&#39;   => 0,
            &#39;hierarchical&#39; => 1,
            &#39;taxonomy&#39;     => &#39;product_cat&#39;,
            &#39;pad_counts&#39;   => 1
        ) ) );

        if ( $product_categories ) {

     get_header( &#39;shop&#39; );

    get_template_part( &#39;templates/page-header&#39; );
    $cs_post_meta    = get_post_meta( $post->ID, &#39;_custom_page_options&#39;, true );
    $cs_page_layout  = ( isset ( $cs_post_meta[&#39;sidebar&#39;] ) ) ? $cs_post_meta[&#39;sidebar&#39;] : &#39;full&#39;;
    $cs_page_column  = ( $cs_page_layout == &#39;full&#39; ) ? &#39;12&#39; : &#39;9&#39;;
    $vc_use_default  = cs_get_option( &#39;vc_use_default&#39; );
    $cs_page_padding = ( $vc_use_default !== true ) ? &#39;md-padding&#39; : &#39;&#39;;
    if( ( $cs_page_layout == &#39;fluid&#39; || isset( $cs_post_meta[&#39;section&#39;] ) ) && $vc_use_default !== true ) {

  get_template_part(&#39;templates/page&#39;, &#39;section&#39;);

} else { ?>
    <section class="main-content <?php echo $cs_page_padding; ?> page-layout-<?php echo $cs_page_layout; ?>">
  <div class="container">
    <div class="row">

      <?php cs_page_sidebar( &#39;left&#39;, $cs_page_layout ); ?>
    
      <div class="col-md-<?php echo $cs_page_column; ?> cs-sidebar-clear">
        <div class="page-content">
     <?php  foreach ( $product_categories as $category ) {
                 $category_link = get_category_link( $category );
                     echo &#39;<a href="&#39;.  esc_url( $category_link ).&#39; "> <div class="col-md-2 b-tab" attr="&#39;.$category->cat_ID.&#39;" >&#39;.$category->name.&#39;</div> </a>&#39;;
            }
?>
        </div>
      </div>
          <?php cs_page_sidebar( &#39;right&#39;, $cs_page_layout ); ?>

        </div>
      </div>
    </section>
        <?php }
        get_footer();
        }else{
            wc_get_template( &#39;archive-product.php&#39; );
        }

If we have a page such as a custom listing (find my vehicle), we change the template.

<?php
/**
 *
 * Template Name: Brand
 * @since 1.0.0
 * @version 1.0.1
 *
 */



get_header();
get_template_part( &#39;templates/page-header&#39; );

$cs_post_meta    = get_post_meta( $post->ID, &#39;_custom_page_options&#39;, true );
$cs_page_layout  = ( isset ( $cs_post_meta[&#39;sidebar&#39;] ) ) ? $cs_post_meta[&#39;sidebar&#39;] : &#39;full&#39;;
$cs_page_column  = ( $cs_page_layout == &#39;full&#39; ) ? &#39;12&#39; : &#39;9&#39;;
$vc_use_default  = cs_get_option( &#39;vc_use_default&#39; );
$cs_page_padding = ( $vc_use_default !== true ) ? &#39;md-padding&#39; : &#39;&#39;;

if( ( $cs_page_layout == &#39;fluid&#39; || isset( $cs_post_meta[&#39;section&#39;] ) ) && $vc_use_default !== true ) {

  get_template_part(&#39;templates/page&#39;, &#39;section&#39;);

} else {
?>
<section class="main-content <?php echo $cs_page_padding; ?> page-layout-<?php echo $cs_page_layout; ?>">
  <div class="container">
    <div class="row">

      <?php cs_page_sidebar( &#39;left&#39;, $cs_page_layout ); ?>
    
      <div class="col-md-<?php echo $cs_page_column; ?> cs-sidebar-clear">
        <div class="page-content">
          <?php
            $args=array(
                   &#39;hide_empty&#39; => 0,
                   &#39;orderby&#39; => &#39;name&#39;,
                   &#39;order&#39; => &#39;ASC&#39;,
                   &#39;taxonomy&#39; => &#39;product_cat&#39;,
                   &#39;depth&#39; => 0,
                   &#39;parent&#39; => 0
                );
                 $res = get_categories($args);
                 foreach($res as $result) {
                 $category_link = get_category_link( $result );
                     echo &#39;<a href="&#39;.  esc_url( $category_link ).&#39; "> <div class="col-md-2 b-tab" attr="&#39;.$result->cat_ID.&#39;" >&#39;.$result->name.&#39;</div> </a>&#39;;
                    } 
          ?>
        </div>
      </div>
      <?php cs_page_sidebar( &#39;right&#39;, $cs_page_layout ); ?>

    </div>
  </div>
</section>
<?php
}
get_footer();

Redirecting the site to https and 301 with htaccess after SSL activation

You have a site, you set it up with http, you are using mysql and php.

You have purchased an SSL certificate or you want to redirect to https with a Let's Encrypt style system.

Especially if you are a WordPress user and have tried dozens of plugins, you have struggled in vain.

RewriteCond %{HTTPS} off # First rewrite to HTTPS: # Don't put www. here. If it is already there it will be included, if not # the subsequent rule will catch it. RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Now, rewrite any request to the wrong domain to use www. # [NC] is a case-insensitive match RewriteCond %{HTTP_HOST} !^www. [NC] RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

URL are not cached by some proxy caching servers error and solution

You have used many cache systems, still "?" Are you having trouble with .css and .js files with the extension?

Because files with this variable are not static, therefore caching cannot be done.

However, the code below is functions.php you place it on the bottom line and bingo.

/** * Remove Query strings from Static Resources. */ function remove_cssjs_ver( $src ) { if( strpos( $src, '?ver=' ) ) $src = remove_query_arg( 'ver', $src ); return $src; } add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 ); add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );

Quick solution for WordPress and Woocommerce slowness problem

As a Woocommerce user, if you have thousands of product ranges, unfortunately, you install many plugins for your cashier system and try to find a solution with Cache systems.

However, since Woocommerce is a system that appeals to the whole world, it is a system that compulsorily runs many unnecessary functions simultaneously. To alleviate this load, you can lighten the distribution of functions that you deem unnecessary, so that the features you do not use are not called by the system and save you speed / time.

Just add the code I have given below to your theme's functions.php file, then you can delete the lines you want or add others. I'm sure you will gain a noticeable speed this way!

add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 ); function child_manage_woocommerce_styles() { //remove generator meta tag remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) ); //first check that woo exists to prevent fatal errors if ( function_exists( 'is_woocommerce' ) ) { //dequeue scripts and styles if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) { wp_dequeue_style( ' woocommerce_frontend_styles' ); wp_dequeue_style( 'woocommerce_fancybox_styles' ); wp_dequeue_style( 'woocommerce_chosen_styles' ); wp_dequeue_style( 'woocommerce_prettyPhoto_css' ); wp_dequeue_script( 'wc_price_slider' ); wp_dequeue_script( 'wc-single-product' ); wp_dequeue_script( 'wc-add-to-cart' ); wp_dequeue_script( 'wc-cart-fragments' ); wp_dequeue_script( 'wc-checkout' ); wp_dequeue_script( 'wc-add-to-cart-variation' ); wp_dequeue_script( 'wc-single-product' ); wp_dequeue_script( 'wc-cart' ); wp_dequeue_script( 'wc-chosen' ); wp_dequeue_script( 'woocommerce' ); wp_dequeue_script( 'prettyPhoto' ); wp_dequeue_script( 'prettyPhoto-init' ); wp_dequeue_script( 'jquery-blockui' ); wp_dequeue_script( 'jquery-placeholder' ); wp_dequeue_script( 'fancybox' ); wp_dequeue_script( 'jqueryui' ); } } }

Adjust mobile component visibility with WordPress and CSS

Since the responsive logic emerged, mobile visibility has started to emerge as one of the most sought after features. At the point where my amateur theme writer friends are thinking about how we can easily handle the options they look for, such as appear on mobile or appear on desktop, you can eliminate this problem by editing a css file with a simple or two code.

For example, let's code over advertising.

<div class="reklamalani">
<!-- reklam kodunu buraya ekleyin -->
</div>
/* don't show on mobile */ @media (max-width:992px){ .reklamalani{display:none} }

Thus, while your ad code that you place in the ad space will be visible on the desktop, it will be invisible on mobile, more precisely on the 992px screen and below.

No Comments
Post a comment

en_USEnglish