Showing posts with label WordPress. Show all posts
Showing posts with label WordPress. Show all posts

Thursday, February 4, 2021

Install Google Analytics to WordPress Without a Plugin

 

Install Google Analytics to WordPress Without a Plugin


In order for Google Analytics to start tracking your visitors, the tracking code mentioned above needs to be present on every page of your site you want to track user behavior on. Usually, that’s all of them. Here’s how you can achieve that manually.

Option A: Insert the Code Into header.php
One of the main ways to add the tracking code to your site is to insert it into your header. This way, it will load on every page.

Most standard themes have a header.php file that is responsible for outputting the site header section. So, you can simply input the Google Analytics code here.

However, when you make changes to theme files, be aware that it’s always best to do it in a child theme. Otherwise, they will get lost when you update your main theme. Child themes are super useful in general and you should definitely read up about them. Also, don’t forget to back up your WordPress site when making any changes like this.

Once you have created your child theme, simply copy the header.php from the main theme into it and start editing. You can do that directly in the WordPress back end via Appearance > Theme Editor.

add google analytics tracking code to wordpress header file via the theme editor Copy and paste the tracking code from Google Analytics into header.php right after the opening <head> tag.
Also, make sure the code is wrapped in <script>...</script> brackets! Otherwise, browsers won’t recognize it for what it is. That’s it! Now save and you are good.


Option B: Use functions.php
Another possibility to add Google Analytics to WordPress without a plugin is to use the functions file. You can do the same thing as we did above, however, instead of adding the tracking code to header.php directly, you insert it into the head section via a function.

To do so, simply edit your (child) theme’s functions.php file and add the following piece of code (but use your own measurement or tracking ID instead of ours):

function ns_google_analytics() { ?>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-B175YGY1T1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());


gtag('config', 'G-B175YGY1T1');
</script>
<?php
}


add_action( 'wp_head', 'ns_google_analytics', 10 );
Save, upload, and from that moment, Google Analytics should start tracking what’s going on on your site.

Wednesday, May 27, 2020

svg file not upload in wordpress

Cannot upload SVG files in WordPress


When we upload the SVG file, we recieve the notification “Sorry, this file type is not permitted for security reasons.”

To Resolve this issue, we need to add the below function in the functions.php files

function cc_mime_types($mimes) {
 $mimes['svg'] = 'image/svg+xml';
 return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');

This will resolve the issue.


Tuesday, April 28, 2020

Wordpress, Gravity form - Remove space between currency symbol and amount

Wordpress, Gravity form - Remove space between currency symbol and amount


Remove space between currency symbol and amount

Please use the below WordPress in the theme Function (functions.php) file

add_filter('gform_currencies', 'update_currency');
function update_currency($currencies) {
    $currencies['GBP'] = array(
        'name' => __('Pound', 'gravityforms'),
        'symbol_left' => '£',
        'symbol_right' => '',
        'symbol_padding' => '',
        'thousand_separator' => ',',
        'decimal_separator' => '.',
        'decimals' => 2);
    return $currencies;
}

Change Currency symbol from left to right

Please use the below WordPress in the theme Function (functions.php) file:

add_filter('gform_currencies', 'update_currency');
function update_currency($currencies) {
    $currencies['GBP'] = array(
        'name' => __('Pound', 'gravityforms'),
        'symbol_left' => '',
        'symbol_right' => '£',
        'symbol_padding' => '',
        'thousand_separator' => ',',
        'decimal_separator' => '.',
        'decimals' => 2);
    return $currencies;
}

Wordpress Yoast, Change breadcrumb trail from post to page

WordPress Yoast, Change breadcrumb trail from  to page


Please use the below WordPress in the theme Function (functions.php) file

add_filter('wpseo_breadcrumb_links', 'wpse_post_breadcrumbs');
// $links are the current breadcrumbs
function wpse_post_breadcrumbs($links) {
    // Use is_singular($post_type) to identify a single CPT
    // This assumes your CPT is called "post" - change it as needed 
if(is_singular('post')) {
        // The first item in $links ($links[0]) is Home, so skip it
        // The second item in $links is Projects - we want to change that
        $links[1] = array('text' => 'News', 'url' => '/news/', 'allow_html' => 1);
    }
    // Even if we didn't change anything, always return the breadcrumbs
    return $links;
}

htaccess 301 redirect from one pages to another page

htaccess 301 redirect from one pages to another page

301 Redirect from page1 to page2

please use the below code in the htaccess file:

RewriteEngine On
Redirect 301 /page1/ /page2/
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Sunday, September 29, 2019

Wordpress, Gravity form - GFCommon::encrypt() is deprecated since version 2.3! Use GFCommon::openssl_encrypt() instead.

After updating  the gravity form ,I’m receiving a few error messages:

Notice : GFCommon::encrypt() is deprecated since version 2.3! Use GFCommon::openssl_encrypt() instead. in /home4/sunshine/public_html/wp-includes/functions.php on line 4435

Deprecated : Function mcrypt_get_iv_size() is deprecated in /home4/sunshine/public_html/wp-content/plugins/gravityforms/common.php on line 5399

Deprecated : Function mcrypt_create_iv() is deprecated in /home4/sunshine/public_html/wp-content/plugins/gravityforms/common.php on line 5402

Deprecated : Function mcrypt_encrypt() is deprecated in /home4/sunshine/public_html/wp-content/plugins/gravityforms/common.php on line 5402

Solution - 

That indicates the reCAPTCHA field is using the old stoken integration method. To upgrade it to use the newer integration method you need to generate new reCAPTCHA api keys for your site and add them to the Forms > Settings page.

That should take care of it for you.

Saturday, August 24, 2019

Wordpress - Contact Form 7 notification open in popup - Bootstrap modal popup

How to add open Contact form 7 Notification / Messages in Modal popup

We can use the Bootstrap modal popup and Contact form 7 Doom Events to create the popup.

Paste the below code in the functions.php, it will work for you (please change the messages as per the requirements):

add_action('wp_footer', 'munesh_Footertext');
function munesh_Footertext() {
echo '<div class="modal fade in formids" id="myModal2" role="dialog" tabindex="-1">
    <div class="modal-dialog">


      <!-- Modal content-->
      <div class="modal-content no_pad text-center">
         <button type="button" class="close" data-dismiss="modal">&times;</button>
        <div class="modal-header heading">
          <h3 class="modal-title" id="MSTitle">Message Sent!</b></h3>
        </div>
        <div class="modal-body">
            <div class="thanku_outer define_float text-center" id="MSBody">Thank you for getting in touch!
            </div>
        </div>
        <div class="modal-footer">
        </div>
      </div>


    </div>
    </div>';
?>
     <script type="text/javascript">
         document.addEventListener( 'wpcf7invalid', function( event ) {
            jQuery('#MSTitle').html('Alert!');
            jQuery('#MSBody').html('One or more fields have an error. Please check and try again.');
             jQuery('#myModal2').modal('show'); }, false );
         </script>
<script type="text/javascript">
         document.addEventListener( 'wpcf7mailfailed', function( event ) {
            jQuery('#MSTitle').html('Alert!');
            jQuery('#MSBody').html('There was an error trying to send your message. Please try again later.');
             jQuery('#myModal2').modal('show'); }, false );
         </script>
<script type="text/javascript">
         document.addEventListener( 'wpcf7mailsent', function( event ) {
            jQuery('#MSTitle').html('Message Sent!');
            jQuery('#MSBody').html('Thank you for getting in touch. We will get back to you ASAP.');
             jQuery('#myModal2').modal('show'); }, false );
         </script>
<style>div.wpcf7-validation-errors, div.wpcf7-acceptance-missing, div.wpcf7-response-output {display:none!important;} .modal{top:25%!important;}</style>
       <?php
}

Link to contact form domain events  - https://contactform7.com/dom-events/


Saturday, April 27, 2019

Contact Form 7 reCAPTCHA not showing


Contact Form 7 latest version not supporting the reCAPTCHA, So, We need to downgrade the Recaptcha plugin,

Steps to Rollback the Contact Form 7 :

  1. Install the Plugin "wp rollback".
  2. After Installing go to the plugins, you will find an option below all the plugins for rollback.
  3. So, rollback the Contact Form 7  from 5.1 to 5.0.5
  4. After this go to integration on the contact form and paste your keys again like you did in the beginning.
  5. Open your contact form on the backend and save it again. Make sure you add the recaptha again
  6. Now go to your front-end and refresh your page.And your done!
Wait for next update with the fix.

No need te install any other plugins.


Thursday, February 28, 2019

WooCommerce Order Cancelled After Successful Payment: Unpaid Order Cancelled – Time Limit Reached

After upgrading to WooCommerce 2.0 and Above, you have experienced the issue  that all the purchased order changes to the “canceled” status. 
In the admin area, all the orders appear as “canceled”  with the message “Unpaid order canceled – time limit reached“. When this happens, you need manually change the statuses of all the canceled orders.
The problem arises due to the Hold Stock feature in WooCommerce Inventory management. In this feature, you can set a certain period of time to hold the stock for an unpaid order.
To Resolve the issue, Go to the admin side of your WordPress store, and navigate to
 WooCommerce > Settings > Products > Inventory.
From this page, you can see that the Hold Stock field is set to 60 minutes by default. If you are using WooCommerce stock management, you can disable this feature by leaving the field blank. Simply delete the value in the field and then save the changes.



Friday, February 15, 2019

Wordpress - How to revert to classic editor / old editor?

How to revert to classic editor / old editor?

if you wants to move back to the old Classic Editor By WordPress Contributors, please install the Plugin
https://wordpress.org/plugins/classic-editor/

Classic Editor is an official plugin maintained by the WordPress team that restores the previous (“classic”) WordPress editor and the “Edit Post” screen. It makes it possible to use plugins that extend that screen, add old-style meta boxes, or otherwise depend on the previous editor.


This plugin also gives you an option to keep both Gutenberg and the Classic editor at the same time. You can configure this in the plugin’s settings.

Simply go to the Settings » Writing page in your WordPress admin area. You will see the option to do this under “Classic editor settings”.
Classic editor settings

Don’t forget to click on the save changes button to store your settings.

You will now be able to see a new link under the Posts menu to create new posts using the classic editor.
Switch to classic editor

You will also be able to edit older articles using the classic editor. Simply go to Posts » All Posts page and you’ll see a ‘Edit (Classic)’ link below posts.
Edit classic


Tuesday, August 21, 2018

WordPress line break not Working

Many WordPress users struggle around this issue of WordPress line break not working. In this article, we discuss some of the possible ways to get around this issue.


1. Use empty classes in HTML Elements
You can make WordPress assume that your HTML elements contain certain attributes. This can be done by Adding attributes to the HTML elements with the use of empty classes. For example:
Avoid writing:
<p>
<br>
<span>
Instead, write:
<p class="">
<br class="">
<span class="">
2. Disable Autop formatting
The Autop() function in WordPress auto formats the paragraphs. The WordPress line break not working is due to the presence of a filter called “wpautop”. The “wpautop” filter executes whenever the content of a blog post is rendered.
We can easily use the remove_filter function to disable the wpautop filter. In the functions.php file you need to add the following code:
remove_filter ('the_content', 'wpautop');
If you use multiple themes, then you need to add this functionality as a plugin. You can place the code within a PHP file inside the /wp-content/plugins directory.

Published Post after Autop disabling

WordPress line breaks Fix1

3. HTML br tag not working: Use TinyMCE Advanced plugin

WordPress has a built-in editor known as the “Visual” editor. At the backend, the editor uses open source editor named “TinyMCE”. If you switch between the Visual Editor and the HTML(Text) editor, the TinyMCE functionality executes a backend filtration process. During this process, the empty tags and the
tags are removed from the post.
The TinyMCE-Advanced plugin adds the option to disable the automatic removal of and
tags. The option to disable/enable WordPress line break is present in the Settings->TinyMCE Advanced panel.
Tiny MCE plugin

Edit Post in Visual Editor without TinyMCE Advanced Plugin installed

WordPress line breaks issue21

Edit Post in Visual Editor with TinyMCE Advanced Plugin installed and disabled auto removal of tags:

 WordPress line breaks Fix21

4. Work with the HTML Editor

This is an easy solution for people who are familiar with HTML. You can avoid working with the Visual editor and switch to the HTML mode in the WordPress editor. The HTML mode lets you control the output and allows you to add or remove line breaks. Just use the
tag wherever you want a line break inserted.

5. Add a filter to replace
tag

Add a filter in the functions.php file which adds a clear attribute to the
tag. When the attribute is added, the
tag is not removed by WordPress.
function clear_br($content) { 
return str_replace("<br/>","<br clear='none'/>", $content);
} 
add_filter('the_content','clear_br');

Post before adding filter

WordPress line breaks filter2

Published post after adding filter

WordPress line breaks filter

6. Create a WordPress Line Break (br) Shortcode

You can add a shortcode to fix the line breaks not working issue in WordPress.
Insert the following shortcode code into the functions.php file:
function add_linebreak_shortcode() {
return '<br />';
}
add_shortcode('br', 'add_linebreak_shortcode' );
Now insert the shortcode shown below wherever you want to insert a space.
[br]

Adding Shortcode in Text Editor

 WordPress line breaks shortcode

Edit Post in Visual Editor

WordPress line breaks shortcode2

Published Post after Adding Shortcode

WordPress line breaks shortcode3

7. HTML Br tag not working – Use CSS

Some developers believe
tags should not be used for styling pages. HTML is a semantic language, not to be used for defining positioning, styling or layout information. Use CSS to generate the style or size of paragraph margins using stylesheets. If you have basic knowledge of CSS, then all you need to add paragraph spaces is add a bottom margin to the tag for the paragraph.
  1. Open the WP admin panel.
  2. Select Appearance > Editor.
  3. Select the file style.css file on the right side. Locate the tag in the style.css file.
    Add the following lines to add gaps above and below the paragraph:
    padding-top:1.0em;
    
    padding-bottom:1.0em;
    Example:
    p {
    margin: 0 0 1.5em;
    }
    After adding those two lines, it will look like this:
    p {
    margin: 0 0 1.5em;
    padding-top:1.0em;
    padding-bottom:1.0em;
    }
  4. Save the file.
All paragraphs get a space above and below. Note that this would add the same amount of space above and below all paragraphs.
 WordPress line breaks margin


Note: this article is taken from https://blog.templatetoaster.com/wordpress-line-break-not-working/ 

Saturday, August 18, 2018

How to Disable WordPress Admin Bar for All Users Except Administrators

Disable Admin Bar for All Users Except for Administrators

Paste this code in your theme’s functions.php file
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
  show_admin_bar(false);
}
}


Disable Admin Bar for All Users

If you want to disable it for all users, then simply put use this code in your theme’s functions.php file
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
  show_admin_bar(false);
}

Friday, August 17, 2018

Wordpress media library not loading images


WordPress media library not loading images or Images are not displaying the images:

Main cause of this issue is the plugin conflict, so please deactivate the plugin one by one and check that your issue resolved or not.

WordPress always update it's software to avoid or overcome issues and it is depreciating the old functions. but some of our plugin using these functions and create problem. So in that case please update the plugin if possible otherwise deactivate it .


Saturday, August 11, 2018

Wordpress pagination 404 error "/page/2" - what to do?


The problem mainly arises because permalinks set to Custom Structure /%category%/%postname%/. I understand WordPress assumes "page" is a post from the category.

That is totally normal behaviour. If you want to remove category base you will need to write some custom rewrite rules, not simple rules I must say.

Configure category base to . (dot), put this code in the functions.php of your theme, or better in a plugin, and flush the rewrite rules (code from this post in Daily Web Kit):

add_filter( 'category_rewrite_rules', 'vipx_filter_category_rewrite_rules' );
function vipx_filter_category_rewrite_rules( $rules ) {
    $categories = get_categories( array( 'hide_empty' => false ) );

    if ( is_array( $categories ) && ! empty( $categories ) ) {
        $slugs = array();
        foreach ( $categories as $category ) {
            if ( is_object( $category ) && ! is_wp_error( $category ) ) {
                if ( 0 == $category->category_parent ) {
                    $slugs[] = $category->slug;
                } else {
                    $slugs[] = trim( get_category_parents( $category->term_id, false, '/', true ), '/' );
                }
            }
        }

        if ( ! empty( $slugs ) ) {
            $rules = array();

            foreach ( $slugs as $slug ) {
                $rules[ '(' . $slug . ')/feed/(feed|rdf|rss|rss2|atom)?/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
                $rules[ '(' . $slug . ')/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
                $rules[ '(' . $slug . ')(/page/(\d)+/?)?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[3]';
            }
        }
    }
    return $rules;
}
For more details , you can check on the url https://wordpress.stackexchange.com/questions/172958/custom-permalink-structure-leads-to-be-404-on-pagination