I have the following piece of PHP code as part of my site theme. Where I am stuck is, if the value of $sec_title contains an apostrophe, then the text doesn't display. But without an apostrophe, it contains fine. How can I amend this to prevent this issue?
<?php
if ( $sec_title ) {
echo do_shortcode( "[onex_section_header
title={$sec_title}
subtitle='{$sec_subtitle}']"
);
} ?>
Try using:
$sec_title = addslashes($sec_title)
before you echo or try switching the double and single quotes around as so
echo do_shortcode('[onex_section_header
title={$sec_title}
subtitle="{$sec_subtitle}"]'
);