• Hello,

    for my websites i have some pages that use custom shortcodes. For these shortcodes there are some .php-files in the wp-directory. I have access to these .php-files and can rewrite them.
    The shortcodes i want to change are about implementing the featured image from some custom post types. When including the image, the alt-text of the image is not implemented, so the alt-text ends up missing on the live-page.
    I already read, that this includes some code like “get_post_meta….”, but i am not that comfortable including code to a php. file.
    Can anyone help me?

    The original code for one of the shortcodes i want to change is

    <?php
    add_shortcode('clients_mixup', 'clients_mixup');
    
    function clients_mixup($atts) {
    
        $terms = get_terms(array(
            'taxonomy' => 'clients_cat',
            'hide_empty' => true,
    	'meta_key' => 'tax_position',
            'orderby' => 'tax_position',
        ));
        $count_terms = count($terms);
    
        $terms_id = array();
        $terms_names = array();
    
        ob_start();
        ?>
        <div class="custom-clients-container-btns">
    
            <div class="controls">
                <button type="button" class="control" data-filter="all"><?php _e("All", "bertschinnovation"); ?></button>
                <?php
                if ($count_terms > 0) {
                    foreach ($terms as $key => $term) {
                        ?>
                        <button type="button" class="control" data-filter=".<?php echo $term->slug; ?>"><?php echo $term->name; ?> </button>
    
                        <?php
                    }
                }
                ?>
    
            </div>
    
            <div class="clients-container custom-clients-container" data-ref="mixitup-container">
                
    
                <?php
                if ($count_terms > 0) {
                    foreach ($terms as $key => $term) {
    
                        $args = array(
                            'posts_per_page' => -1,
                            "suppress_filters" => false,
                            'post_type' => 'clients_type',
                            'tax_query' => array(
                                array(
                                    'taxonomy' => 'clients_cat',
                                    'field' => 'term_id',
                                    'terms' => $term->term_id
                                )
                            )
                        );
                        $clients_array = get_posts($args);
                        $count_clients = count($clients_array);
                        if ($count_clients > 0) {
                            ?>
    
                            <?php
                            foreach ($clients_array as $key => $client) {
    
                                $image = get_stylesheet_directory_uri() . "/assets/images/default-img.jpg";
                                if (has_post_thumbnail($client->ID)) {
                                    $image = wp_get_attachment_image_src(get_post_thumbnail_id($client->ID), 'thumbnail');
                                    $image = $image[0];
                                }
                                ?>
    
                                <div class="item mix <?php echo $term->slug; ?>" data-ref="mixitup-target">
                                    <div class="box-content">
                                        <img src="<?php echo $image; ?>" alt="">
                                    </div>
                                </div>
    
                            <?php }
                            ?>
    
                            <?php
                        }
                    }
                }
                ?>
    
                <div class="gap"></div>
                <div class="gap"></div>
                <div class="gap"></div>
            </div>
    
        </div>
    
        <?php
        return ob_get_clean();
    }
    
    • This topic was modified 3 years, 6 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Moved to Fixing WordPress, this is not an Developing with WordPress topic.

    Where did you find that file? In a theme or plugin? The reason I am asking is that if that code is supported here on this site (as a theme or plugin) then I can direct you to the right place to raise that support topic.

    Thread Starter janeric

    (@janeric)

    I found it via the FTP. It’s located under the wp-content/themes/theme-name-child/includes

    Thanks for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘custom shortcode php. – include alt-text for images’ is closed to new replies.