Categories
Allgemein

10 WordPress developing tips

If you’ve decided to get into WordPress development, you’ve just opened up a whole new world of possibilities to build amazing websites. WordPress is easy to use, but there’s way more to it than that. There are plenty of possibilities when it comes to WordPress development, including changing the backend/admin area to your own preferences and adding additional functionalities.

So, get ready to step up your game when it comes to building with WordPress!

10 WordPress developing tips

If you’ve decided to get into WordPress development, you’ve just opened up a whole new world of possibilities to build amazing websites. WordPress is easy to use, but there’s way more to it than that. There are plenty of possibilities when it comes to WordPress development, including changing the backend/admin area to your own preferences and adding additional functionalities.

So, get ready to step up your game when it comes to building with WordPress!

01. wpdb for custom database queries

Utilize the $wpdb class for executing custom database queries.


    global $wpdb;
    $results = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}posts WHERE post_type = 'post'");

02. Nonces in AJAX calls

When making AJAX requests, include a nonce for security.


    $nonce = wp_create_nonce('my_custom_nonce');

03. wp_remote_get() for external HTTP requests

Easily make external API requests.


    $response = wp_remote_get('https://api.example.com/data');
    $body = wp_remote_retrieve_body($response);

04. Customize the WP admin menu

Adjust the order and visibility of admin menu items in the functions.php file.


    function custom_admin_menu_order($menu_order) {
        return array(
            'index.php', // Dashboard
            'edit.php?post_type=page', // Pages
            'edit.php', // Posts
            // Add more menu items as needed
        );
    }
    add_filter('custom_menu_order', '__return_true');
    add_filter('menu_order', 'custom_admin_menu_order');

05. wp_add_inline_style() for inline styles

Add inline styles to your WordPress themes or plugins.


    function add_custom_styles() {
        wp_add_inline_style('my-style', 'body { background-color: #f1f1f1; }');
    }
    add_action('wp_enqueue_scripts', 'add_custom_styles');

06. Custom excerpts without shortcodes

Modify the default excerpt length without using manual excerpts or the more tag.


    function custom_excerpt_length($length) {
        return 50; // Change to desired length
    }
    add_filter('excerpt_length', 'custom_excerpt_length');

07. Dynamic page templates

Create dynamic page templates based on custom conditions.


    function custom_page_template() {
        if (is_page('my-custom-page')) {
            include('custom-page-template.php');
            exit;
        }
    }
    add_action('template_redirect', 'custom_page_template');

08. Custom post statuses

Add custom post statuses beyond ‘draft’ and ‘publish’.


    function custom_post_statuses() {
        register_post_status('custom_status', array(
            'label' => 'Custom Status',
            'public' => true,
            'exclude_from_search' => false,
            'show_in_admin_all_list' => true,
            'show_in_admin_status_list' => true,
        ));
    }
    add_action('init', 'custom_post_statuses');

09. Custom image sizes in themes

Declare custom image sizes in your theme.


    add_image_size('custom-size', 300, 200, true); // Width, Height, Crop

10. Using wp_list_pluck()

Extract a certain field from an array of objects.


    $post_titles = wp_list_pluck(get_posts('post_type=post'), 'post_title');