Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
kellenmace
/
edit-slug-button-missing-in-wordpress.php
Created
Sep 12, 2016
Star
0
Fork
0
Star
Code
Revisions
1
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Fix Edit Slug Button Missing Issue in WordPress
Raw
edit-slug-button-missing-in-wordpress.php
<?php
/**
* Changes all post links to the format 'newsroom/news/yyyy/mm/dd/%postname%'
*
* @param string $url The post URL.
* @param WP_Post $post The post.
* @return string $url The modified URL.
*/
function
km_filter_post_links
(
$
url
,
$
post
) {
if
(
'post'
===
$
post
->
post_type
) {
// If $url contains %postname% placeholder
if
(
false
!==
strpos
(
$
url
,
'%postname%'
) ) {
$
slug
=
'%postname%'
;
}
elseif
(
$
post
->
post_name
) {
$
slug
=
$
post
->
post_name
;
}
else
{
$
slug
=
sanitize_title
(
$
post
->
post_title
);
}
$
date
=
DateTime
::
createFromFormat
(
'Y-m-d H:i:s'
,
$
post
->
post_date
)->
format
(
'Y/m/d'
);
$
url
=
home_url
(
user_trailingslashit
(
'newsroom/news/'
.
$
date
.
'/'
.
$
slug
) );
}
return
$
url
;
}
add_filter
(
'post_link'
,
'km_filter_post_links'
,
10
,
2
);
/**
* Filter posts preview links to point to the correct URL.
*
* @param string $preview_link The preview link URL.
* @param WP_Post $post The post.
* @return string $url The modified link URL.
*/
function
km_filter_post_preview_link
(
$
preview_link
,
$
post
) {
if
(
'post'
===
$
post
->
post_type
) {
$
preview_link
=
add_query_arg
(
array
(
'p'
=>
$
post
->
ID
,
'preview'
=>
'true'
,
),
home_url
(
'/'
) );
}
return
$
preview_link
;
}
add_filter
(
'preview_post_link'
,
'km_filter_post_preview_link'
,
10
,
2
);
Sign up for free
to join this conversation on GitHub
. Already have an account?
Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.