Cloud version of single.php

Posted in: Newspaper
Post count: 10

Firstly, well done on the 10.4 update; upgrade went smoothly and pagespeed scores are excellent.

Before the Cloud Templates I would copy single.php into a child theme to allow me to add PHP code to the template. Is this possible with the Cloud Templates?

I use template_redirect action to call in a single.php file currently as there are dynamically generated pages from a database.

Ant

Post count: 21065

Hello!

Unfortunately, this is not possible for the Cloud Templates.

Thank you!

Post count: 10

Thank you for the quick response.

For others who may be here looking in the future, what I have done to work around this is to create a shortcode that produces the required PHP output and then popped that shortcode into a page using the Column Text Element.


add_shortcode('myshortcode', 'my_shortcode');

function my_shortcode($atts) {
extract(shortcode_atts(array(
'name' => FALSE
), $atts));

$name = esc_html($atts['name']);

$output = 'Hello '.$name;

return $output;
}

Then within the child theme functions.php file I have added


function my_add_rewrite_rules( $rules ) {
$new_rules = array();
$new_rules['^something/(.*)/?'] = 'index.php?pagename=dynamicpage&x=$matches[1]';
return $new_rules + $rules;

}
add_action('rewrite_rules_array', 'my_add_rewrite_rules');

All pages in the form https://mysite.com/something/xxxx gets rewritten to the page and then the shortcode can pull the x query variable to produce the correct output.

Hope this helps someone.

Ant

Viewing 3 posts - 1 through 3 (of 3 total)
The forum ‘Newspaper’ is closed to new topics and replies.