Here I by no means cover Wordpress in amount of detail. Wordpress posts cover my own experience in setting up blogs which may or may not help others going through a similar process.Pagename: wordpress - Wordpress
Category:Array
Post Count: 5Category:Wordpress
Pagename: wordpress - Wordpress
Pagename: wordpress - Wordpress
jQuery – test jQuery is running
jQuery or $ object:- Open your browser’s developer tools (usually by pressing F12 or Ctrl+Shift+I/Cmd+Option+I).
- Navigate to the “Console” tab.
- Type
jQueryand press Enter. - Type
$and press Enter.
If jQuery is loaded, these commands will return the jQuery function or object. If jQuery is not loaded, you will likely receive an “Uncaught ReferenceError: jQuery is not defined” or similar error.
- In the console, type
jQuery.fn.jqueryand press Enter. - Alternatively, type
$.fn.jqueryand press Enter.
- In the console, type
if (typeof jQuery != 'undefined') { console.log("jQuery is loaded!");} else { console.log("jQuery is NOT loaded.");}and press Enter.
Leave a Reply
Pagename: wordpress - Wordpress
WordPress – Moving wordpress installation to subfolder
After installing wordpress into home directory (ie public_html ) I realised it is not as clean as one would want when working with numerous addon domains. Far better, in my opinion, to have the wordpress folders and files in a separate sub-folder for the sake of tidyness.
Sites I used for this information were:
The steps I took are:
-
- Create sub-folder to use
- Move wordpress folders & files to new sub-folder
- Logged into the wordpress console using the url with the sub-folder included (ie example.com/sub-folder/wp-admin)
- Specify sub-folder in wordpress’s general settings:
![]()
Steps taken to move from home folder to separate sub-folder:
Leave a Reply
Pagename: wordpress - Wordpress
WordPress – Merge wp_postmeta table (local version with online)
When extra information is required to be stored for a specific record in ‘wp_posts’, it can be stored in the ‘wp_postmeta’ table. One such bit of information is when an attached image is to be used as the site-icon. I realised this when I added an icon (ie a favicon) to a local version of my site only to not see it not show up when I uploaded the files to the online version. I had updated the wp_post table but this also did not rectify the situation. The wp_postmeta table specifies that the image is to be used as the site icon.
I wasn’t sure how well the online data would match with my local version so I did some checks which I describe here for reference:
1. wp_postmeta was exported to local drive and a temporary copy was made (called wp_postmetab).
2. Next I did some exploration. I did a union of both tables and grouped them. In this case, most records matched with the exception of ‘_edit_lock’ field. This made sense as it would change when a post was opened and updated. In this case, I was able to delete the ‘_edit_lock’ records in 1 table and use those from the other table.
Using the query shown below, I looked for ‘counts’ of 1 which would indicate either unique entries or non-matching entries. I was ignoring ‘meta_id’ as it is not used/recorded elsewhere as far as I have been able to determine (this site details that: wp-staging.com/docs/the-wordpress-database-structure/#wp_posts).
Cases where a unique value existed in either table would just be added to the merged table. If the information is needed, it will be there and if not, no big deal that it is there.
For clarity, the query below produces a union of two tables with extra columns to show when records are grouped and which database/table the record(s) come from.
[code lang=”sql”]
SELECT Count(*) as cnt, SUM(DB1) as Sum1, SUM(DB2) as Sum2, UN.* FROM
(
SELECT 1 as DB1, 0 as DB2, pm.* FROM DB_Name.wp_postmeta as pm
UNION ALL
SELECT 0 as DB1, 1 as DB2, pmb.* FROM DB_Name.wp_postmetab as pmb
) UN
GROUP BY post_id, meta_key, meta_value;
[/code]
3. For those cases where post_id and meta_key matched but meta_value did not, a decision had to be made for each record. I created a copy of the combined tables without the ‘meta_id’ column (this column was added after). Using ‘UNION’ rather than ‘UNION ALL’ keeps distinct values only. I compared against the previous temporary table for those records that needed to be deleted or amended.
[code lang=”sql”]
CREATE TABLE TempPostMeta
SELECT post_id, meta_key, meta_value FROM DB_Name.wp_postmeta as pm
UNION
SELECT post_id, meta_key, meta_value FROM DB_Name.wp_postmetab as pmb;
ALTER TABLE TempPostMeta
ADD meta_id bigint(20) unsigned AUTO_INCREMENT PRIMARY KEY FIRST;
[/code]
4. Once TempPostMeta table was considered a suitable replacement I truncated the data in the wp_postmeta and replaced with the data from TempPostMeta table.
[code lang=”sql”]
TRUNCATE TABLE DB_Name.wp_postmeta;
INSERT INTO DB_Name.wp_postmeta(meta_id, post_id, meta_key, meta_value)
SELECT meta_id, post_id, meta_key, meta_value from DB_Name.TempPostMeta;
[/code]
5. I then did the same steps to add the data to the online version and tested which found everything to be working as it should be.
Leave a Reply
Pagename: wordpress - Wordpress
WordPress – Add Custom Content Plugin
Editing posts directly within the wordpress editor can be a nuisance when wordpress inserts ‘p’ tags and the like. Sometimes I want to edit HTML in actual HTML editor which allows me greater control over the presentation of the content.
To facilitate this I have added a plugin which inserts HTML from a custom file based on the post id.
Content is added from a file within the ‘custom’ folder:
“current-theme-child\Custom\Content\Custom-Content-82.php”
This file can be edited and viewed in a standard HTML editor. The number within the file name is the post id which can be found from url’s and other ways. When the content is shown, the content within the wordpress editor is shown first followed by the content within the file.
Here is the plugin code as to date:
[code lang=”php”]
?php
/**
* Plugin Name: Include Custom Content
* Plugin URI: https://dalestake.com/2019/11/26/wordpress-add-custom-content-plugin/
* Description: Inserts files stored in ‘Custom/Content/’ into the content section (ie within the body of the post)
* Version: 0.1
* Author: Dale Anderson
* Author URI: NA
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: include-custom-content
*/
// Check if a custom content file exists…
add_action(‘wp_head’,’CheckForCustomContent’);
$BaseCustomDir = "";
$CurID = "";
$FilePath = "";
function CheckForCustomContent()
{
global $BaseCustomDir;
global $CurID;
global $FilePath;
// A folder for custom files is manually added to the appropriate location
$BaseCustomDir = get_stylesheet_directory()."/Custom";
// The post id is used to correctly identify the files to include
$CurID = get_the_ID();
$FilePath = $BaseCustomDir."/custom-css/custom-css-".$CurID.".css";
// Only want to include custom content when a single post is being shown
if( is_singular() )
{
// Check for custom CSS files. Link if file exists.
if(file_exists ( $FilePath))
{
$RelFilePath = get_stylesheet_directory_uri()."/Custom/custom-css/custom-css-".$CurID.".css";
// Custom CSS file exists so it is included
?>
<!– Custom CSS via plugin –>
<link rel="stylesheet" type="text/css" href="<?php echo $RelFilePath; ?>" />
<?php
}
// Check for custom content. Link if file exists. Filename must be exact.
$FilePath = $BaseCustomDir."/Custom-content/custom-content-".$CurID.".php";
//error_log("FilePath before insert content function: ".$FilePath);
if(file_exists ( $FilePath))
{
//error_log("FilePath for content: ".$FilePath);
add_filter(‘the_content’, ‘InsertCustomContent’);
}
}
};
[/code]
My intent is to make adjustments to allow similar files to be included such as scripts and also to allow control over where the content is placed.