WordPress common use functions + jQuery + ACF

//wp get nav
wp_nav_menu( array( 'theme_location' =--> 'mobile-menu', 'container' => 'Mobile nav' ) );

//get ID by slug
$id = get_page_by_path( 'contact' );

//get title by ID
get_the_title($id);

//get page, post url by slug
echo get_permalink($id); 

//get theam directory url
get_template_directory_uri(); 

function custom_excerpt_length( $length ) {
  return 55;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
  function custom_excerpt_more( $more ) {
    return '';
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );


function add_theme_scripts() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
wp_enqueue_style( 'stylecss', get_template_directory_uri() . '/css/style.css', array(), time(), 'all');
 
wp_enqueue_script( 'mainp', get_template_directory_uri() . '/js/main.js', array (  ), time(), true);
}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );


function register_my_menu() {
    register_nav_menu('header-menu',__( 'Header Menu' ));
    register_nav_menu('footer-menu1',__( 'Footer Menu 1' ));
    register_nav_menu('footer-menu2',__( 'Footer Menu 2' ));
    register_nav_menu('footer-menu3',__( 'Footer Menu 3' ));
}
add_action( 'init', 'register_my_menu' );

// Upload SVG files
function add_svg_to_uploads($file_types){
      $new_filetypes = array();
      $new_filetypes['svg'] = 'image/svg+xml';
      $file_types = array_merge($file_types, $new_filetypes );
      return $file_types;
}
add_action('upload_mimes', 'add_svg_to_uploads');

add ACF option page
if( function_exists('acf_add_options_page') ) {
  acf_add_options_page();
}
$variable = get_field('field_name', 'option');

// check if the repeater field has rows of data
if( have_rows('repeater_field_name') ):

 	// loop through the rows of data
    while ( have_rows('repeater_field_name') ) : the_row();

        // display a sub field value
        the_sub_field('sub_field_name');

    endwhile;

else :

    // no rows found

endif;


//jQuery smooth scroll by class name to id
$( document ).ready(function() {
	
$(".our-cost-policy, .our-team, .our-approach").click(function() { 
		did = $(this).attr('class');
	    $('html, body').animate({
	        scrollTop: $("#"+did).offset().top
	    }, 2000);
	});
)};

Leave a Reply

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