Last active
May 17, 2016 02:08
-
-
Save inakagawa/6d0f3cb6d3888d2fd489b1a4c3bef7df to your computer and use it in GitHub Desktop.
WordPress: Permalink from slug - shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sc_getpermalink_by_path($args){ | |
$atts = shortcode_atts( | |
array( | |
'slug' => '', | |
'post_type' => 'page', | |
'ret_type' => 'OBJECT' | |
), | |
$args, 'sc_path'); | |
$pageobj = get_page_by_path($atts['slug'], $atts['ret_type'], $atts['post_type']); | |
$fullpath = ''; | |
if($pageobj){ | |
$id = $pageobj->ID; | |
$fullpath = get_permalink($id); | |
}else{ | |
$fullpath = get_home_url(); | |
} | |
return $fullpath; | |
} | |
add_shortcode('sc_path', 'sc_getpermalink_by_path'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方