最好的WordPress技巧和技巧开发人员可以在其中工作

Hacks and Tricks WordPress tutorial: while WordPress happens to be the most hotly pursued CMS platform of all, you do need to branch out of the defaults to make your WordPress website gain singularity. The job becomes a tad easier, simply for the fact that we know how customizable the WordPress is. Extending WordPress beyond defaults thus seems like a feasible endeavor. Now, there are gazillion of themes and plugins making their way to the WordPress realm by the hour, and consequentially, it’s getting harder to get your website stand apart from the growing clutter.

Hacks and Tricks WordPress教程:尽管WordPress恰好是最受追捧的CMS平台,但您确实需要跳出默认设置,以使WordPress网站获得独特性。 这项工作变得容易一点,仅仅是因为我们知道WordPress的可定制性。 因此,将WordPress扩展到默认值以上似乎是可行的努力。 现在,成千上万的主题和插件按小时开始进入WordPress领域,因此,越来越难以使您的网站脱颖而出。

Before the problem of plenty snowballs into serious issues for you, let’s take a look at some extremely WordPress hacks that let you strengthen your website and also perform multitude of features and fixes in no time.

在大量的滚雪球问题变成严重的问题之前,让我们看一下一些WordPress极端黑客,这些黑客可以使您增强网站并立即执行多种功能和修复。

1.在侧边栏中显示最新帖子 (1. Display Latest Post in Sidebar)

This is one of those elementary, yet very decisive WordPress hacks that should be accomplished without putting in too much efforts. The feature is useful if it is applied on a theme. The process is quite simple to do. All you need just open the sidebar.php file and add the below mentioned code to display the latest post in the sidebar area.

这是那些基本但决定性的WordPress骇客之一,无需过多努力即可完成。 如果将该功能应用于主题,则该功能很有用。 该过程非常简单。 您只需要打开sidebar.php文件并添加下面提到的代码,即可在sidebar区域中显示最新帖子。


<ul>
<?php wp_get_archives('type=postbypost&limit=5'); ?>
</ul>

<ul>
<?php wp_get_archives('type=postbypost&limit=5'); ?>
</ul>

2.使用无瑕的JPG图像 (2. Use Flawless JPG Images)

Displaying high-quality images enhances the overall visual appeal and character of your website. It’s a good practice to breed confidence and trust among your visitors, not to mention the space and bandwidth the truncated files (without affecting the quality) save. To ensure your images are of supreme quality, insert the following code to your theme’s function.php file.

显示高质量图像可以增强网站的整体视觉吸引力和个性。 这是在访问者之间建立信任和信任的好习惯,更不用说截断的文件(不影响质量)节省的空间和带宽了。 为了确保您的图像具有最高的质量,请在主题的function.php文件中插入以下代码。


add_filter( 'jpg_quality', 'high_jpg_quality' );
function high_jpg_quality() {
  return 100;
}

add_filter( 'jpg_quality', 'high_jpg_quality' );
function high_jpg_quality() {
  return 100;
}

3.准确的网址 (3. Accurate URLs)

Having a proper URL structure is extremely important to prevent your visitors getting riled up whenever they encounter 404 error. An accurate URL structure is also crucial in terms of SEO ranking of a website. To ensure your URLs are free from invalid characters, you can add this function in esc_url() function:

拥有正确的URL结构对于防止访问者在遇到404错误时变得异常恼火非常重要。 正确的URL结构对于网站的SEO排名也至关重要。 为了确保您的网址中没有无效字符,您可以在esc_url()函数中添加以下函数:


$my_url = 'http://www.myexamplewebsite.com/?example=true';
$url = esc_url( $mywebsite_url );

$my_url = 'http://www.myexamplewebsite.com/?example=true';
$url = esc_url( $mywebsite_url );

4.利用一般分类法功能 (4. Make Use of General Taxonomy Functions)

WordPress comes packed with a great deal of taxonomy functions that let you manage and handle a variety of taxonomy functions including built-in tags and categories. The codex WordPress.org provides a handy list of all these functions that help you make things like categories, posts, bookmark functions, taxonomy functions much more streamlined.

WordPress附带了大量分类功能,可让您管理和处理各种分类功能,包括内置标签和类别。 WordPress.org抄本提供了所有这些功能的便捷列表,可帮助您简化类别,帖子,书签功能,分类法功能。

5.在WordPress中创建会话 (5. Create Sessions Within WordPress)

Setting up of sessions is a useful practice of storing information between pages and it has been widely followed by a number of websites. WordPress doesn’t allow this function to be used internally. However, you can set up a session of your own using the following code. But before you actually start the process, be ensure about checking IP addresses and adding some protection just to be on a safer side.

建立会话是一种在页面之间存储信息的有用做法,许多网站已经广泛采用它。 WordPress不允许在内部使用此功能。 但是,您可以使用以下代码来建立自己的会话。 但是,在您真正开始此过程之前,请确保检查IP地址并添加一些保护,以便更加安全。


add_action( 'init', 'example website session_start' );
function example_session_start() {
   if ( !session_id() ) {
      session_start();
   }
}

add_action( 'init', 'example website session_start' );
function example_session_start() {
   if ( !session_id() ) {
      session_start();
   }
}

6.解决发布RSS时的问题 (6. Fixing the Issues When a Post Goes RSS)

There are times when you suddenly observe that there are some mistakes in your post after finally publishing it. It’s quite easy to fix such errors, but it’s already too late for your subscribers- as your post has gone live and has got published their RSS feeds.

有时候,您在最终发布文章后突然发现自己的帖子中存在一些错误。 修复此类错误非常容易,但是对于您的订阅者来说已经太迟了-因为您的帖子已经上线并且已经发布了他们的RSS feed。

There is no need to worry about. You can still fix such errors and edit your live post. All you need is simply add the following code in your functions.php file.

无需担心。 您仍然可以修复此类错误并编辑实时帖子。 您只需要在您的functions.php文件中添加以下代码即可。


function publish_later_on_feed($where) {
  global $wpdb;
  if ( is_feed() ) {
    $time_now = gmdate('Y-m-d H:i:s');
    $time_delay = '15'; // integer
    $time_span = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
    $where = " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$time_now') > $time_delay ";
  }
  return $where;
}
add_filter('posts_where', 'publish_later_on_feed');

function publish_later_on_feed($where) {
  global $wpdb;
  if ( is_feed() ) {
    $time_now = gmdate('Y-m-d H:i:s');
    $time_delay = '15'; // integer
    $time_span = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
    $where = " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$time_now') > $time_delay ";
  }
  return $where;
}
add_filter('posts_where', 'publish_later_on_feed');

7.更改默认Gravatar (7. Making Changes in the Default Gravatar)

This hack is really awesome if you seriously want to revamp the overall appearance of your theme. You can go about it by adding the following code in your functions.php file.

如果您想认真修改主题的整体外观,那么此技巧真的很棒。 您可以通过在functions.php文件中添加以下代码来解决此问题。


if ( !function_exists('linkedin_addgravatar') ) {
	function linkedin_addgravatar( $avatar_defaults ) {
		$myavatar = get_bloginfo('template_directory').'/gravatar.gif';
                //default avatar
		$avatar_defaults[$mynew avatar] = 'My new gravtar';
		return $avatar_defaults;
	}
	add_filter( 'avatar_defaults', 'linkedin_addgravatar' );
}

if ( !function_exists('linkedin_addgravatar') ) {
	function linkedin_addgravatar( $avatar_defaults ) {
		$myavatar = get_bloginfo('template_directory').'/gravatar.gif';
                //default avatar
		$avatar_defaults[$mynew avatar] = 'My new gravtar';
		return $avatar_defaults;
	}
	add_filter( 'avatar_defaults', 'linkedin_addgravatar' );
}

8.定制仪表盘徽标 (8. Customizing the Dashboard Logo)

WordPress users can opt to add their own logo in the dashboard to give a more personal touch to the installation process. This is a pretty useful hack and looks great on client websites. Just use the following code:

WordPress用户可以选择在仪表板中添加自己的徽标,以使安装过程更具个人风格。 这是一个非常有用的技巧,在客户端网站上看起来不错。 只需使用以下代码:


add_action('admin_head', 'custom_logo');
function custom_logo() {
  echo '<style type="text/css"><!-- #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.gif) !important; } --></style>';
}

add_action('admin_head', 'custom_logo');
function custom_logo() {
  echo '<style type="text/css"><!-- #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.gif) !important; } --></style>';
}

9.摆脱登录页面上的错误消息 (9. Getting Rid of The Error Message on the Login Page)

Whenever the user enters your website and provides a username or password that is wrong, an error message is displayed on the login page, asking user to provide the correct information. If a hacker guesses the information correctly, chances of getting your site hacked increases. To block hackers access the information of your website insert the following filter. Please note- Site with multiple authors can’t perform this hack.

每当用户进入您的网站并提供错误的用户名或密码时,登录页面上都会显示一条错误消息,要求用户提供正确的信息。 如果黑客正确猜出了这些信息,那么增加您网站被黑客入侵的机会。 要阻止黑客访问您网站的信息,请插入以下过滤器。 请注意-具有多位作者的网站无法执行此hack。


add_filter('login_errors',create_function('$a', "return null;"));

add_filter('login_errors',create_function('$a', "return null;"));

结语 (Wrapping Up)

Discovering the capabilities of your website and extending it in a way that’s most value-adding for you as well as to your readers creates a credible environment for your visitors to access your website and enlist themselves as repeat visitors. Once you get the grasp of the hacks, you can efficiently channelize your content management efforts on the subject that helps you plan for the future and tighten the bolts of your website.

发现您网站的功能并以对您和读者来说最具附加值的方式扩展它,为访问者访问您的网站并吸引自己成为重复访问者创造了一个可靠的环境。 掌握了这些技巧后,您就可以有效地将内容管理工作引导到该主题上,以帮助您计划未来并拧紧网站的螺栓。

翻译自: https://www.script-tutorials.com/best-of-wordpress-hacks-and-tricks-developers-can-work-at/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值