How to change the page title from functions.php

If you refer to the post title you need to hook your function to the_title filter like explained in the codex. add_filter(‘the_title’, ‘my_custom_title’, 10, 2); If you refer to the HTML meta in your page then you need to hook your function to document_title_parts filter explained here. add_filter(‘document_title_parts’, ‘my_custom_title’, 10, 2); The two filters work … Read more

ACF Plugin – Random Gallery Image with wp_get_attachment_image()

<?php $images = get_field(‘gallery’); $size=”full”; // (thumbnail, medium, large, full or custom size) $rand = array_rand($images, 1); if( $images ): ?> <?php echo wp_get_attachment_image( $images[$rand][‘ID’], $size ); ?> <?php endif; ?> This code should work. array_rand() return key if second param set to 1 or array with keys if second param > 1

How to create an array for a CPT post ID to use in an IF/WHILE statement

You can use the fields parameter of WP_Query to get just IDs back, then iterate over them with a foreach loop: $args = array( ‘post_type’ => ‘services’, ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, ); $query = new WP_Query( $args ); if( $query->have_posts() ){ foreach( $query->posts as $id ){ the_field( ‘the_field’, $id ); } } else … Read more

Thumbnails generated from PDF in the “Media” section – how to show them in theme template?

To get the attachment’s icon, you can use wp_get_attachment_image(). For example, let’s say I’ve uploaded a Word doc and it’s got the ID 1234: // Parameter 3 – ‘true’ – tells WP to treat this as an icon. $img_tag = wp_get_attachment_image( 1234, ‘thumbnail’, true ); // $img_tag contains: // <img width=”48″ height=”64″ // src=”http://example.com/wp-includes/images/media/document.png” // … Read more

Advanced Custom Fields/User Role Editor – how to hide ACF for certain users?

The admin_menu action will hide the ACF menu, in this example for not-admins. And admin_head will block the access if the URL is accessed directly. E.g.: http://example.com/wp-admin/edit.php?post_type=acf and http://example.com/wp-admin/edit.php?post_type=acf&page=acf-settings add_action( ‘admin_menu’, ‘wpse_59032_remove_acf_menu’, 9999 ); add_action( ‘admin_head-edit.php’, ‘wpse_59032_block_acf_screens’ ); add_action( ‘admin_head-custom-fields_page_acf-settings’, ‘wpse_59032_block_acf_screens’ ); function wpse_59032_remove_acf_menu() { /* if not our allowed users, hide menu */ if … Read more

How to Increment ID value within ACF Repeater Field Loop

Try using a “counter” variable for the loop maybe? <?php if ( get_field(‘ingredients-list’) ) { echo ‘<ul class=”ingredientsList”>’; $count=0; while ( has_sub_field(‘ingredients-list’) ) { echo ‘<li class=”ingredient” itemprop=”ingredients”> <label for=”check-‘. $count .'”> <input type=”checkbox” class=”check” id=”check-‘. $count .'”> ‘; if ( get_sub_field(‘quantity’) ) echo ‘<span class=”quantity”>’ . get_sub_field(‘quantity’) . ‘</span> ‘; if ( get_sub_field(‘measurement’) ) … Read more

ACF if / else checkbox [closed]

Small fix for you 🙂 <?php if( in_array( “Yes”, get_field( ‘news__item–external’ ) ) ) { ?> <a href=”https://wordpress.stackexchange.com/questions/170396/<?php echo the_field(“news__item–external-url’); ?>” class=”more icon–chev”>View full article</a> <? } else { ?> <a href=”https://wordpress.stackexchange.com/questions/170396/home.php”>Home</a> <?php } ?> The code to fix was: <php } else { <a href=”https://wordpress.stackexchange.com/questions/170396/home.php”>Home</a> } ?> You was missing the end php tag … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)