<script>
const userName = 'Ken';
const target = document.getElementById('start-button');
function sayHello(e){
console.log('Hello, ' + this.name);
};
target.addEventListener('click', {name: userName, handleEvent: sayHello});
</script>
[WordPress] 各種URL、PATH取得方法まとめ
定数
URL例 | コード | 説明 |
---|---|---|
/www/html/wp | ABSPATH | WordPressのルートディレクトリ |
/www/html/wp/wp-content | WP_CONTENT_DIR | コンテンツディレクトリのフルパス |
http://localhost/wp-content | WP_CONTENT_URL | コンテンツディレクトリのURL |
/www/html/wp/wp-content/plugins | WP_PLUGIN_DIR | プラグインディレクトリのフルパス |
http://localhost/wp-content/plugins | WP_PLUGIN_URL | プラグインディレクトリのURL |
/wp-content/uploads | UPLOADS | マルチサイトのみデフォルトで設定されている。 シングルサイト時は未設定だが自己責任で設定可 |
関連項目
WordPress ディレクトリ: | ||
home_url() | ホーム URL | http://www.example.com |
site_url() | サイトディレクトリ URL | http://www.example.com または http://www.example.com/wordpress |
admin_url() | 管理画面ディレクトリ URL | http://www.example.com/wp-admin |
includes_url() /en | インクルードディレクトリ URL | http://www.example.com/wp-includes |
content_url() /en | コンテンツディレクトリ URL | http://www.example.com/wp-content |
plugins_url() /en | プラグインディレクトリ URL | http://www.example.com/wp-content/plugins |
wp_upload_dir() /en | アップロードディレクトリ URL (配列を返す) | http://www.example.com/wp-content/uploads |
Facebook広告
キャンペーン名「」
1日の予算「」
スケジュール「」
オーディエンス->AIに任せる
配置FacebookとInstagram
見た人が最初に目にする画像とコピー(メインテキスト)
URL
エラーのとはコールトゥーアクション「詳しくはこちら」
TickTokやBuzzVideoでも
指定のドメインでなければ処理終了
//指定のドメインでなければ処理終了
if($_SERVER['HTTP_HOST']!='xxxxxx.com') {
exit(1);
}
wpでcron処理をfunctions.php内に設置
// 自動実行用関数
function my_auto_function() {
・・・
処理
・・・
}
add_action ( 'my_auto_function_cron', 'my_auto_function' );
// cron登録処理
if ( !wp_next_scheduled( 'my_auto_function_cron' ) ) { // 何度も同じcronが登録されないように
date_default_timezone_set('Asia/Tokyo'); // タイムゾーンの設定
wp_schedule_event( strtotime('2017-06-29 02:00:00'), 'daily', 'my_auto_function_cron' );
}
プラグイン「WP Crontrol」を組み込むことで、簡単にcron動作状況を確認出来る。
// 自動実行用関数
function my_auto_function() {
$content = 'テンプレートの内容です';
$title = 'テンプレートのタイトルです';
$post = array (
'post_content' => $content,
'post_title' => $title,
'post_status' => 'draft',
'post_type' => 'post'
);
wp_insert_post( $post );
}
add_action ( 'my_auto_function_cron', 'my_auto_function' );
// cron登録処理
if ( !wp_next_scheduled( 'my_auto_function_cron' ) ) { // 何度も同じcronが登録されないように
date_default_timezone_set('Asia/Tokyo');
wp_schedule_event( strtotime('2017-06-30 02:00:00'), 'daily', 'my_auto_function_cron' );
}
秒間隔で実行する
function cron_add_20sec( $schedules ) {
$schedules['20sec'] = array(
'interval' => 20,
'display' => __( '20秒1回' )
);
return $schedules;
}
add_filter( 'cron_schedules', 'cron_add_20sec' );
wp_cronは、60秒ごとに起動するので、60秒以下の上記のような設定では、期待通りの動作はしない。
「wp_schedule_event」は、同じことをリピートしたい場合に使います。特に「毎週・毎日・毎時間・毎分」などの場合に使うと便利です。
「wp_schedule_single_event」は、繰り返しがない場合や、変則的なスケジュール(15日後・毎月特定の日など)の場合に使います。
function hoge_function() {
//
//実行したい内容
//
}
add_action ( 'hoge_add_cron', 'hoge_function' );
//cron登録処理
//スケジュール2重登録防止
if ( !wp_next_scheduled( 'hoge_add_cron' ) ) {
//
//9時間差がある
//
wp_schedule_event( strtotime(date("Ymd 3:00:00")), 'daily', 'hoge_add_cron' );
}
日本時間の朝9時にクーロンを起動したい場合は、-9時間した日付をUNIXタイムで指定する必要があります。例:日本の朝4時に起動させたい場合
strtotime(date('Ymd 19:00:00'));
「wp_schedule_single_event」は最初のarg(日時を指定する変数)に指定した時刻に1度だけスケジュールを実行します。
1度だけ起動するのは、日付を固定日付にした場合で、日付を動的に設定すれば、好きな時に1度だけ起動できるので、リピート起動のようなことができます。
動的にする場合は「mktime」を使うと便利です。
下記の例だと15分ごとにスケジュール起動します。
function hoge_function() {
//
//実行したい内容
//
}
add_action ( 'hoge_add_cron', 'hoge_function' );
//cron登録処理
//スケジュール2重登録防止
if ( !wp_next_scheduled( 'hoge_add_cron' ) ) {
//
//9時間差がある
//
wp_schedule_single_event( strtotime(date('Ymd H:00:00', mktime(date('H'), date('i')+15, 0, date('m'), date('d'), date('Y')))), 'hoge_add_cron' );//7時
}
毎月15日に起動させたい場合も「wp_schedule_single_event」を使えばできます。
メモ
mktimeで「date(‘m’)+1」と指定しているので、翌月からスタートになります。当月分は自分で起動させる必要があります。
function hoge_function() {
//
//実行したい内容
//
}
add_action ( 'hoge_add_cron', 'hoge_function' );
//cron登録処理
//スケジュール2重登録防止
if ( !wp_next_scheduled( 'hoge_add_cron' ) ) {
//
//9時間差がある
//
wp_schedule_single_event( strtotime(date('Ymd H:i:s', mktime(0, 0, 0, date('m')+1, 15, date('Y')))), 'hoge_add_cron' );//7時
}
phpでtwitterに自動投稿する
<?php
// TwitterOAuthを利用するためautoload.phpを読み込み
require __DIR__ . 'twitteroauth-master/autoload.php';
// TwitterOAuthクラスをインポート
use Abraham\TwitterOAuth\TwitterOAuth;
// Twitter APIを利用するための認証情報。xxxxxxxxの箇所にそれぞれの情報をセット
const TW_CK = 'xxxxxxxx'; // Consumer Keyをセット
const TW_CS = 'xxxxxxxx'; // Consumer Secretをセット
const TW_AT = 'xxxxxxxx'; // Access Tokenをセット
const TW_ATS = 'xxxxxxxx'; // Access Token Secretをセット
// TwitterOAuthクラスのインスタンスを作成
$connect = new TwitterOAuth( TW_CK, TW_CS, TW_AT, TW_ATS );
// Twitter API v2. を利用する場合
// $connect->setApiVersion('2');
// ツイートしたい文字列を配列にセット
$array = array(
'tweet01',
'tweet02',
'tweet03'
);
// 配列をランダムにして、先頭を取得
shuffle( $array );
$tweet = $array[0];
// ツイートを投稿
$result = $connect->post(
'statuses/update',
array(
'status' => $tweet
)
);
設定で、https::〜にしたらログイン出来なくなったとき
WordPress アドレス (URL) | |
---|---|
サイトアドレス (URL) |
上記のせっていで、https://〜としたら、ログイン出来なくなったとき
①「phpmyadmin」にログインして、「データベース」から修正します。
②「wp_options」を選択肢します。
③「siteurl」と「home」の内容を、https://〜からhttp://〜に変更する。
タイトルにダイヤマークを設置
.entry-header .entry-title {
position: relative;
margin-left: 8px;
color: darkslategray;
padding-left: 8px;
}
.entry-header .entry-title::before {
content: "";
position: absolute;
bottom: 12px;
left: -10px;
display: block;
width: 12px;
height: 12px;
background: darkorange;
transform: rotate(45deg) skew(10deg, 10deg);
}
simple membership のショートコード
会員ログイン
[swpm_login_form]
無料会員登録
[swpm_registration_form]
プロフィール
[swpm_profile_form]
パスワードリセット
[swpm_reset_form]
支払いボタン
[swpm_payment_button id=75]
テキストを追加する
[swpm_payment_button id=75 button_text="今すぐ登録"]
ストライプ支払いボタンのカスタムスタイル
クラス名を追加してcssを設定できるようになります。
[swpm_payment_button id=75 button_text="今すぐ支払う" class="my-stripe-button"]
有料会員登録後にすぐユーザー登録をする
[swpm_thank_you_page_registration]
WordPress管理画面の投稿一覧にスラッグを追加する(固定ページも)
/* 投稿一覧にスラッグ追加 */
function add_posts_columns_slug($columns) {
$columns['slug'] = 'スラッグ';
return $columns;
}
function add_posts_columns_slug_row($column_name, $post_id) {
if( $column_name == 'slug' ) {
$slug = get_post($post_id) -> post_name;
echo esc_attr($slug);
}
}
add_filter( 'manage_posts_columns', 'add_posts_columns_slug' );
add_action( 'manage_posts_custom_column', 'add_posts_columns_slug_row', 10, 2 );
/* 固定ページ一覧にスラッグ追加 */
function add_page_columns_slug($columns) {
$columns['slug'] = 'スラッグ';
return $columns;
}
function add_page_column_slug_row($column_name, $post_id) {
if( $column_name == 'slug' ) {
$slug = get_post($post_id) -> post_name;
echo esc_attr($slug);
}
}
add_filter( 'manage_pages_columns', 'add_page_columns_slug');
add_action( 'manage_pages_custom_column', 'add_page_column_slug_row', 10, 2);