1
I am creating a Wordpress template for a client, and I need to insert layouts in the pages, so I created the following shortcode on functions.php
of the template:
<?php
function shortcode_add_layout( $atts , $content = null ) {
extract(
shortcode_atts(
array(
'add' => 'home',
),
$atts
)
);
$file = get_template_directory_uri() . '/layouts/' . $add . '.php';
if (!file_exists($file)) {
echo file_get_contents($file);
} else {
echo 'Oops, layout not found';
}
}
add_shortcode('layout', 'shortcode_add_layout');
# [layout add='home']
?>
With this, I place the files with the layouts in the folder '/layouts', inside the folder of the template, and when calling the shortcode, displays the contents of the file.
This was the solution that I found, because no type of code with includes worked, however it is taking too long to load, include
common?
See if that reply in the community Wordpress Development can help you.
– NoobSaibot