编辑“文章更新.查看文章”链接

时间:2011-04-21 作者:Marco

是否可以编辑“帖子更新。查看帖子”链接并完全删除“查看帖子”?是否还要将“Post”更改为cpt的名称?

谢谢大家!

更新时间:

这是我使用的代码,它工作起来很有魅力。我希望这对其他人有帮助!

在我的示例中,我使用“Contact”作为我的cpt:

enter image description here

add_filter(\'post_updated_messages\', \'contact_updated_messages\');
function contact_updated_messages( $messages ) {

$messages[\'contact\'] = array(
0 => \'\', // Unused. Messages start at index 1.
1 => sprintf( __(\'Contact updated. <a href="%s">View Contact</a>\'), esc_url( get_permalink($post_ID) ) ),
2 => __(\'Custom field updated.\'),
3 => __(\'Custom field deleted.\'),
4 => __(\'Contact updated.\'),
/* translators: %s: date and time of the revision */
5 => isset($_GET[\'revision\']) ? sprintf( __(\'Contact restored to revision from %s\'), wp_post_revision_title( (int) $_GET[\'revision\'], false ) ) : false,
6 => sprintf( __(\'Contact published. <a href="%s">View Contact</a>\'), esc_url( get_permalink($post_ID) ) ),
7 => __(\'Contact saved.\'),
8 => sprintf( __(\'Contact submitted. <a target="_blank" href="%s">Preview Contact</a>\'), esc_url( add_query_arg( \'preview\', \'true\', get_permalink($post_ID) ) ) ),
9 => sprintf( __(\'Contact scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Contact</a>\'),
  // translators: Publish box date format, see http://php.net/date
  date_i18n( __( \'M j, Y @ G:i\' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __(\'Contact draft updated. <a target="_blank" href="%s">Preview Contact</a>\'), esc_url( add_query_arg( \'preview\', \'true\', get_permalink($post_ID) ) ) ),
);

return $messages;
}

2 个回复
SO网友:Milo

您可以筛选更新消息:add_filter(\'post_updated_messages\', \'your_message_function\');

查看/wp管理/编辑表单高级。php查看默认消息的设置位置。

SO网友:benklocek

为了使这项工作适用于所有CPT,我找到了一个要点,可以将其抽象为一个简单的函数来插入函数。php

https://gist.github.com/benklocek/2b510994c3ecbe508af6

/**
* Replaces "Post" in the update messages for custom post types on the "Edit"post screen.
* For example, for a "Product" custom post type, "Post updated. View Post." becomes "Product updated. View Product".
*
* @param array $messages The default WordPress messages.
*/

function pico_custom_update_messages( $messages ) {
global $post, $post_ID;

$post_types = get_post_types( array( \'show_ui\' => true, \'_builtin\' => false ), \'objects\' );

foreach( $post_types as $post_type => $post_object ) {

    $messages[$post_type] = array(
        0  => \'\', // Unused. Messages start at index 1.
        1  => sprintf( __( \'%s updated. <a href="%s">View %s</a>\' ), $post_object->labels->singular_name, esc_url( get_permalink( $post_ID ) ), $post_object->labels->singular_name ),
        2  => __( \'Custom field updated.\' ),
        3  => __( \'Custom field deleted.\' ),
        4  => sprintf( __( \'%s updated.\' ), $post_object->labels->singular_name ),
        5  => isset( $_GET[\'revision\']) ? sprintf( __( \'%s restored to revision from %s\' ), $post_object->labels->singular_name, wp_post_revision_title( (int) $_GET[\'revision\'], false ) ) : false,
        6  => sprintf( __( \'%s published. <a href="%s">View %s</a>\' ), $post_object->labels->singular_name, esc_url( get_permalink( $post_ID ) ), $post_object->labels->singular_name ),
        7  => sprintf( __( \'%s saved.\' ), $post_object->labels->singular_name ),
        8  => sprintf( __( \'%s submitted. <a target="_blank" href="%s">Preview %s</a>\'), $post_object->labels->singular_name, esc_url( add_query_arg( \'preview\', \'true\', get_permalink( $post_ID ) ) ), $post_object->labels->singular_name ),
        9  => sprintf( __( \'%s scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview %s</a>\'), $post_object->labels->singular_name, date_i18n( __( \'M j, Y @ G:i\' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ), $post_object->labels->singular_name ),
        10 => sprintf( __( \'%s draft updated. <a target="_blank" href="%s">Preview %s</a>\'), $post_object->labels->singular_name, esc_url( add_query_arg( \'preview\', \'true\', get_permalink( $post_ID ) ) ), $post_object->labels->singular_name ),
        );
}

return $messages;
}
add_filter( \'post_updated_messages\', \'pico_custom_update_messages\' );
注意:中的函数名add_filter 方法和实际函数定义的要点不同。这已在上面粘贴的片段中更正

结束

相关推荐

过滤NEXT_POSTS_LINK和PREVICE_POSTS_LINK的URL

我正在与qTranslate plugin 创建多语言网站。除了在next_posts_link &;previous_posts_link 模板标记。当用户选择了其他语言时,URL应更改为:http://mysite.com/test/page/2 (对于默认语言)到http://mysite.com/fr/test/page/2 (法语)该插件提供了使用qtrans_convertURL($url) 作用我遇到的问题是找到一个合适的钩子或过滤器,允许我通过next\\u posts\\u lin