Useful links:


For wordpress sites I build, I insert the google analytics (ga) tracking code into the html head section via a plugin. The code for this is shown below. Alternatively, it is relatively easy to slip the tracking code directly into the ‘header(s)’ template (Located: your-site.com\wp-content\themes\active-theme\header.php) as described by google analytics on the ‘tracking-code’ page. However, I prefer the ‘cleaner’ approach of separating the code into a separate file. So much easier to read if it is ever required…
I also use the WordPress function ‘is_user_logged_in’ to remove most of my visits to the site as I am typically signed in to my WP admin account.
Here is the code:
<?php /* Plugin Name: Site-Name Google Analytics Plugin Plugin URI: http://--relevant url? Description: Adds the Google analytics tracking code to ... Site-Name Author: Author name Version: 1.0 */ /* Do not insert tracking code if the user is logged in (ie internal traffic) This is wrapped in a function (insert_ga_tracking() ) so it can be loaded with the 'init' hook. An error can be produced otherwise... */ function insert_ga_tracking() { if ( ! is_user_logged_in() ) { add_action( 'wp_head', 'Site-Name_google_analytics', 10 ); function Site-Name_google_analytics() { ?> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-12345678-1"> </script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-12345678-1'); </script> <?php } } } add_action('init', 'insert_ga_tracking');
To use this code…
Create a php file in the folder location: Site-Name/wp-content/plugins/ and add the script above to this file.
The tracking code between ‘‘ and ‘‘ needs the tracking code supplied by google for your site (located in the admin/tracking for your google analytics property).
‘Site-Name’ in the code above can be changed to the target site or removed (in all four locations…). I add the site name as a check to ensure the right tracking code goes to the right site location.
Then, in the WP Admin dashboard, go to ‘installed plugins’ and activate the plugin which should be displayed with the name you specified ‘Plugin name’.
That should be all there is to it but don’t forget to test it using google analytic’s testing feature.
Summarizing the steps explained in the WP Codex for creating a child theme.
Source:https://developer.wordpress.org/themes/advanced-topics/child-themes/
/* Theme Name: Twenty Fifteen Child Theme URI: http://example.com/twenty-fifteen-child/ Description: Twenty Fifteen Child Theme Author: John Doe Author URI: http://example.com Template: twentyfifteen Version: 1.0.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: light, dark, two-columns, right-sidebar... Text Domain: twenty-fifteen-child */
<?php add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); function my_theme_enqueue_styles() { // Example: 'parent-style' is 'twentyfifteen-style' // for the Twenty Fifteen theme $parent_style = 'parent-style'; wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme() ); get('Version')); } ?>
Steps I use to import data (ie posts, settings info etc) from my online hosting account to the MySQL database on my localhost (ie my own pc). This will not import any new plugins, updates or ploaded images or files. This post covers exporting and importing the wordpress Database.
NOTE: I do not claim this is the most efficient or the most secure method. It is simply how I do it.
I use:
Steps in short:
Details:
1. Backup database from localhost using MySQL client. Screen shots shown here are using MySQL workbench…
Export as a single file:
Archive the file for backup. I typically give the file a more meaningful name and I will select the ‘include create schema’ box as shown below:
2. Export data from online hosting site using phpMyAdmin
i. Access hosting account using cpanel
ii. Locate and open phpMyAdmin (in cpanel Database category)
iii. Use phpMyAdmin to export a copy of the desired online database by:
a) Locate database in database list
b) Use ‘Export’ function to view export options:
c) Leave most options but select ‘Add drop table’ to renew all tables within database. Note: select ‘create database’ as well if you intend on refreshing the database completely (you will need to drop the database).
d) Select ‘go’ to run the export function and save the outputed file in a suitable location (ie archives)
3) In exported SQL file, look for the site domain name that is specified in ‘wp_options’ table script. For example, looking for site dradma.com…
Modify these lines to work on the localhost. For example….
4. Import data from SQL file created in phpMyAdmin using selected MySQL client program. Below shows MySQL workbench process…open SQL file (phpMyAdmin export), run SQL script and check the database has successfully been imported.
Documentation covers this in detail: https://en.support.wordpress.com/code/posting-source-code/
Notes:
[code language="vb"] ...your code here... [/code]
Example (using VB):
[code language=”vb”]
Sub ShowAllWorkSheets()
‘Makes all worksheets visible
Dim CWS As Worksheet
For Each CWS In ThisWorkbook.Worksheets
CWS.Visible = xlSheetVisible
Next CWS
End Sub
[/code]
Produces:
Sub ShowAllWorkSheets() 'Makes all worksheets visible Dim CWS As Worksheet For Each CWS In ThisWorkbook.Worksheets CWS.Visible = xlSheetVisible Next CWS End Sub