PHP code example of mwdelaney / acf-flexible-content-blocks
1. Go to this page and download the library: Download mwdelaney/acf-flexible-content-blocks library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mwdelaney / acf-flexible-content-blocks example snippets
`{r, engine='php', count_lines}
/**
* Make the first block title an h1 and subsequent blocks default to h2
*/
remove_filter( 'fcb_set_block_htag', 'block_htag_level', 10 );
add_filter( 'fcb_set_block_htag', 'custom_htag_level', 10, 2 );
function custom_htag_level($title, $htag) {
if($GLOBALS['fcb_rows_count'] == 0) {
$htag = 'h1';
} else {
$htag = 'h2';
}
return '<' . $htag . '>' . $title . '</' . $htag . '>';
}
`{r, engine='php', count_lines}
/**
* Give the first block an additional class of 'block-first'
*/
add_filter( 'fcb_set_block_wrapper_classes', 'custom_block_wrapper_classes' );
function custom_block_wrapper_classes($classes) {
if($GLOBALS['fcb_rows_count'] == 0) {
$classes[] = 'block-wrapper-first';
}
return $classes;
}
`{r, engine='php', count_lines}
/**
* Give the first block an additional class of 'block-first'
*/
add_filter( 'fcb_set_block_classes', 'custom_block_classes' );
function custom_block_classes($classes) {
if($GLOBALS['fcb_rows_count'] == 0) {
$classes[] = 'block-first';
}
return $classes;
}
`{r, engine='php', count_lines}
/**
* Give the first block an ugly green border
*/
add_filter( 'fcb_set_block_wrapper_styles', 'custom_block_styles' );
function custom_block_styles($styles) {
if($GLOBALS['fcb_rows_count'] == 0) {
$styles[] = 'border: 1px solid green;';
}
return $styles;
}
`
/**
* Add layouts to ACFFCB
*/
function my_layouts() {
// The name of the class we keep our layouts in
return 'myLayouts';
}
add_action( 'acf/init', function() {
// Remove the plugin's set default set of layouts
remove_filter ('fcb_get_layouts', 'fcb_layouts_class', 99, 2);
// Add my own layouts
add_filter ('fcb_get_layouts', 'my_layouts', 99, 2);
});
// Extend the original class to (
'key' => __FUNCTION__,
'name' => 'call_to_action',
'label' => 'Call to Action',
'display' => 'block',
'sub_fields' => array (
// Call to Action
$FCBFields->tab_cta(),
$FCBFlexibleContent->cta(),
// Tab Endpoint
$FCBFields->tab_endpoint(),
)
)
)
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.