Ask questions about WordPress courses

9 short but useful WordPress codes

Text change code read more ..

Paste the following code into the file function.php. Checked everything and everything works fine. Maybe not everything is so beautiful, but the codes work.

function new_excerpt_more($more) {
       global $post;
	return '<br /><br /><b><a class="moretag" href="'. get_permalink($post->ID) . '"> Читать урок полностью...</a></b>';
}
add_filter('excerpt_more', 'new_excerpt_more');

Inserting a search string anywhere in the template. I also checked everything.

<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
  <div>
    <input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="Search" />
  </div>
</form>

Adding Current User Avatar to WordPress Template

 <?php
        global $current_user;
        get_currentuserinfo();
        echo get_avatar( $current_user->ID, 64 );
 ?>

An example of what happens:

Counting the number of PDF files, in the WordPress media library

function pdf_count(){
	$query_pdf_args = array(
		'post_type' => 'attachment',
		'post_mime_type' =>'application/pdf',
		'post_status' => 'inherit',
		'posts_per_page' => -1,
		);
	$query_pdf = new WP_Query( $query_pdf_args );
	echo $query_pdf->post_count;
}

You can use the short function to insert quantities into your site:

pdf_count();

Title change

Changing the default text in the admin panel. When entering a title.

function title_text_input( $title ){
     return $title = 'Enter new title';
}
add_filter( 'enter_title_here', 'title_text_input' );

 

Adding a Gravatar Instead of a Favicon

Optimizing the admin area for users. Adding a Gravatar Instead of a Favicon, a trifle in order to pay attention to your site.

function gravatar_favicon() {
        $GetTheHash = md5(strtolower(trim(get_bloginfo('admin_email'))));
        return 'https://www.gravatar.com/avatar/' . $GetTheHash . '?s=16';
}
function favicon() {
	if ( is_user_logged_in() ) {
			echo '<link rel="Shortcut Icon" type="image/x-icon" href="'.gravatar_favicon().'" />';
	}
}
add_action('wp_head', 'favicon');

 

Adding a caption for the post thumbnail

Everything is simple, if you need to leave a comment for your clients, then this can be done with the following code.

add_filter( 'admin_post_thumbnail_html', 'add_featured_image_html');
function add_featured_image_html( $html ) {
    return $html .= '<p>This is some sample text that can be displayed within the feature image box.</p>';
}

By adding the code you will get a signature under the thumbnail block in the admin panel.

Removing the URL field in the comment form

add_filter('comment_form_default_fields', 'unset_url_field');
function unset_url_field($fields){
    if(isset($fields['url']))
       unset($fields['url']);
       return $fields;
}

 

Hide pages from the list for Administrators when editing

This is a great little snippet., which will exclude pages, based on ID from the list of pages from administrators. Just add this snippet to functions.php your topic WordPress and update the array with your pages ID to hide them.

add_action( 'pre_get_posts' ,'exclude_this_page' );
function exclude_this_page( $query ) {
        if( !is_admin() )
                return $query;
        global $pagenow;
        if( 'edit.php' == $pagenow && ( get_query_var('post_type') && 'page' == get_query_var('post_type') ) )
        $query->set( 'post__not_in', array(23,28,30) ); // page id
        return $query;
}

 

I hope the new code snippets in the “WordPress Technical Issues” section will be useful to you.. Good luck with development.


Buy WordPress hosting
/* WordPress tutor
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal