WordPress パス・URLの取得

Wordpress
関数解説出力
ABSPATHインストール場所C:\xampp\htdocs\xampp\example/(ローカル)
/var/www/html/example/(サーバ)
admin_url()管理画面URLhttps://example.com/wp-admin/
content_url()wp-contentディレクトリURLhttps://example.com/wp-content
get_attachment_link($id)添付ファイルのIDを渡すと
添付ページの URL を返す
https://example.com/?attachment_id=$id
get_author_posts_url($author)投稿者別のアーカイブページURLhttps://example.com/?author=0
get_bloginfo($show)デフォルトは’name’でサイト名を返す。与える引数による違いは以下の通り。
$show = ‘admin_email’admin@example.com
$show = ‘atom_url’https://example.com/home/feed/atom
$show = ‘charset’UTF-8
$show = ‘comments_atom_url’https://example.com/home/comments/feed/atom
$show = ‘comments_rss2_url’https://example.com/home/comments/feed
$show = ‘description’WordPress blog
$show = ‘html_type’text/html
$show = ‘language’ja-JP
$show = ‘name’TestSite
$show = ‘pingback_url’https://example.com/home/wp/xmlrpc.php
$show = ‘rdf_url’https://example.com/home/feed/rdf
$show = ‘rss2_url’https://example.com/home/feed
$show = ‘rss_url’https://example.com/home/feed/rss
$show = ‘stylesheet_directory’https://example.com/home/wp/wp-content/themes/largo
$show = ‘stylesheet_url’https://example.com/home/wp/wp-content/themes/largo/style.css
$show = ‘template_directory’https://example.com/home/wp/wp-content/themes/largo
$show = ‘template_url’https://example.com/home/wp/wp-content/themes/largo
$show = ‘text_direction’ltr
$show = ‘url’https://example.com/home
$show = ‘version’5.2
$show = ‘wpurl’https://example.com/home/wp
get_category_link($id)カテゴリーアーカイブページヘのリンク
https://example.com/?cat=0
get_day_link($year, $month, $day)日別アーカイブページのリンク。
デフォルトは現在の日。
https://example.com/?m=20200421
get_edit_user_link($user_id)ユーザー情報編集画面用URLhttps://example.com/wp-admin/profile.php
get_feed_link()Feed URLhttps://example.com/?feed=rss2
get_month_link($year, $month)年別アーカイブページURL
デフォルトは現在の年度。
https://example.com/?m=202004
get_page_link($id)固定ページのパーマリンクURLhttps://example.com/?page_id=$id
get_permalink($id)記事idを渡すとURLのスラッグを返す。
パーマリンク設定によって異なる
https://example.com/?p=$id
get_post_type_archive_link($posttype)カスタム投稿タイプのアーカイブページを返す。
get_post_type_archive_link( get_post_type() )など
https://example.com/$posttype
get_stylesheet()現在適用されているテーマ
(スタイルシート)のディレクトリ
twentyten-child
get_stylesheet_directory()現在適用されているテーマ
(スタイルシート)のディレクトリ
/var/www/html/example/wp-content/themes/twentyten-child
get_stylesheet_directory_uri()現在適用されているテーマを
URI表記で返す
https://example.com/wp-content/themes/twentyten-child
get_stylesheet_uri()現在適用されているテーマ
(スタイルシート)のパス
/var/www/html/example/wp-content/themes/twentyten-child/style.css
get_tag_link($id)タグアーカイブページヘのリンク。
IDで指定してスラッグで返ってくる。
https://example.com/?tag=wordpress
get_template_directory()親テーマのディレクトリ/var/www/html/example/wp-content/themes/twentyten
get_template_directory_uri()親テーマのURIhttps://example.com/wp-content/themes/twentyten
get_term_link($id)カスタム分類アーカイブページヘのリンク。
タクソノミーが無いとWP_Error Objectを返す
https://example.com/custom-taxonomy
get_theme_root()テーマのディレクトリ/var/www/html/example/wp-content/themes
get_theme_root_uri()親テーマのディレクトリhttps://example.com/wp-content/themes
get_year_link($year)年別アーカイブページのリンク。
デフォルトは現在の年度。
https://example.com/?m=2015
home_url($path, $scheme)$pathにはホームURLからの相対パス。
$schemeはhttpかhttpsもしくはrelative(相対パス)
https://example.com/$path
includes_url()wp-includesのディレクトリを返すhttps://example.com/wp-includes/
plugin_dir_path(__FILE__)現在のファイルのディレクトリを返す。
pluginファイルに書けばプラグインのパスを返すが、
必ずしもpluginのディレクトリを返すとは限らない
/var/www/html/example/wp-content\themes\twentyten-child/
plugins_url()プラグインディレクトのパスhttps://example.com/wp-content/plugins
site_url()サイトのアドレスを表示。
スラッシュは付かない
https://localhost/xampp/example
the_permalink()現在のページのパスhttps://example.com/
WP_CONTENT_DIRwp-contentディレクトリのパス/var/www/html/example/wp-content
wp_get_shortlink($id)短縮URL、ショートリンクを表示する。
パーマリンク設定で長いスラッグにしている
場合に外部プログラムへ短いURLを渡したい
場合などに使う
https://example.com/?p=$id
WP_LANG_DIRlanguagesディレクトリのパス/var/www/html/example/wp-content/languages
wp_login_url()ログイン画面のパスhttps://example.com/wp-login.php
wp_logout_url()ログアウト用のパスhttps://example.com/wp-login.php?action=logout&_wpnonce=0000000000
wp_lostpassword_url()ログアウト用のパスhttps://example.com/wp-login.php?action=lostpassword
WP_PLUGIN_DIRプラグインディレクトのパス/var/www/html/example/wp-content/plugins
wp_registration_url()ユーザー登録用のパスhttps://example.com/wp-login.php?action=register
wp_upload_dir($time)アップロードディレクトリ URL。
配列で返ってくる。
$timeはデフォルトはnull。$time = ‘path‘
/var/www/html/example/wp-content/uploads
$time = ‘url‘https://example.com/wp-content/uploads
$time = ‘subdir‘
$time = ‘basedir‘/var/www/html/example/wp-content/uploads
$time = ‘baseurl‘https://example.com/wp-content/uploads
$time = ‘error‘bool(false)

コメント

タイトルとURLをコピーしました